Ejemplo n.º 1
0
 def get_default_fields(self):
     default_fields = super(SourceVersionExportSerializer, self).get_default_fields()
     if self.opts.view_name is None:
         self.opts.view_name = self._get_default_view_name(self.opts.model)
     default_fields.update(
         {
             'parentVersionUrl': HyperlinkedResourceVersionIdentityField(related_attr='parent_version', view_name=self.opts.view_name),
             'previousVersionUrl': HyperlinkedResourceVersionIdentityField(related_attr='previous_version', view_name=self.opts.view_name),
         }
     )
     return default_fields
Ejemplo n.º 2
0
    def get_default_fields(self):
        fields = super(ResourceVersionSerializer, self).get_default_fields()

        if self.opts.view_name is None:
            self.opts.view_name = self._get_default_view_name(self.opts.model)

        if self.opts.versioned_object_view_name is None:
            object = self.object[0] if self.many and len(
                self.object) > 0 else self.object
            if object:
                versioned_object_model = object.versioned_object_type.model_class(
                )
                self.opts.versioned_object_view_name = self._get_default_view_name(
                    versioned_object_model)

        ret = self._dict_class()

        if 'version_url' not in fields:
            url_field = HyperlinkedResourceVersionIdentityField(
                view_name=self.opts.view_name, )
            ret['version_url'] = url_field

        versioned_object_field_name = self.opts.versioned_object_field_name or 'versioned_object_url'
        if versioned_object_field_name not in fields:
            url_field = HyperlinkedVersionedResourceIdentityField(
                view_name=self.opts.versioned_object_view_name, )
            ret[versioned_object_field_name] = url_field

        ret.update(fields)
        fields = ret

        return fields