def _to_representation(self, instance): """Uncached `to_representation`.""" if self.enable_optimization: representation = self._faster_to_representation(instance) else: representation = super(WithDynamicSerializerMixin, self).to_representation(instance) if settings.ENABLE_LINKS: # TODO: Make this function configurable to support other # formats like JSON API link objects. representation = merge_link_object(self, representation, instance) if self.debug: representation['_meta'] = { 'id': instance.pk, 'type': self.get_plural_name() } # tag the representation with the serializer and instance return tag_dict(representation, serializer=self, instance=instance, embed=self.embed)
def to_representation(self, instance): """Modified to_representation method. Arguments: instance: A model instance or data object. Returns: Instance ID if the serializer is meant to represent its ID. Otherwise, a tagged data dict representation. """ if self.id_only(): return instance.pk else: if self.enable_optimization: representation = self._faster_to_representation(instance) else: representation = super( WithDynamicSerializerMixin, self ).to_representation(instance) if settings.ENABLE_LINKS: # TODO: Make this function configurable to support other # formats like JSON API link objects. representation = merge_link_object( self, representation, instance ) # tag the representation with the serializer and instance return tag_dict( representation, serializer=self, instance=instance, embed=self.embed )
def to_representation(self, instance): """Modified to_representation method. Arguments: instance: A model instance or data object. Returns: Instance ID if the serializer is meant to represent its ID. Otherwise, a tagged data dict representation. """ if self.id_only(): return instance.pk else: if self.enable_optimization: representation = self._faster_to_representation(instance) else: representation = super(WithDynamicSerializerMixin, self).to_representation(instance) if settings.ENABLE_LINKS: # TODO: Make this function configurable to support other # formats like JSON API link objects. representation = merge_link_object(self, representation, instance) if self.debug: representation['_meta'] = { 'id': instance.pk, 'type': self.get_plural_name() } # tag the representation with the serializer and instance return tag_dict(representation, serializer=self, instance=instance, embed=self.embed)
def to_representation(self, instance): """Modified to_representation method. Arguments: instance: A model instance or data object. Returns: Instance ID if the serializer is meant to represent its ID. Otherwise, a tagged data dict representation. """ id_only = self.id_only() if (self.get_format() == 'admin' and self.is_root()): id_only = False if id_only: return instance.pk else: if self.enable_optimization: representation = self._faster_to_representation(instance) else: representation = super(WithDynamicSerializerMixin, self).to_representation(instance) query_params = self.get_request_attribute('query_params', {}) if (settings.ENABLE_LINKS and 'exclude_links' not in query_params): representation = merge_link_object(self, representation, instance) if self.debug: representation['_meta'] = { 'id': instance.pk, 'type': self.get_plural_name() } # tag the representation with the serializer and instance return tag_dict(representation, serializer=self, instance=instance, embed=self.embed)