Skip to content

Instantly share code, notes, and snippets.

@db0company
Created May 15, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save db0company/de40c9431b9f3c64f697 to your computer and use it in GitHub Desktop.
Save db0company/de40c9431b9f3c64f697 to your computer and use it in GitHub Desktop.
class ElementSerializerMixin(object):
[...]
creation = serializers.SerializerMethodField('get_creation')
modification = serializers.SerializerMethodField('get_modification')
ELEMENT_FIELDS = ('creation', 'modification',)
def _get_date(self, date):
return date.strftime('%Y-%m-%dT%H:%M:%SZ')
def get_creation(self, obj):
return _get_date(obj.creation)
def get_modification(self, obj):
return _get_date(obj.modification)
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment