> A suggestion though, is to be able to declare serializers in a
> similar fashion as models or forms.
Actually that's a fair point, yup - the proposal could be made a little
closer to the existing Forms and Models APIs.
Something along these lines...
class ModelPKField(SerializerField):
def get_value(self, obj, key):
return unicode(obj.pk)
class ModelNameField(SerializerField):
def get_value(self, obj, key):
return unicode(obj._meta)
class ModelFieldSetField(SerializerField):
def get_value(self, obj, key):
return FieldsSerializer().serialize(obj)
class RelatedPKField(SerializerField):
def get_value(self, obj, key):
return unicode(getattr(obj, key).pk)
class FieldsSerializer(Serializer):
"""
Serializes only the fields on a model.
"""
class Meta:
exclude = ('id', 'pk')
default_related_field = RelatedPKField()
class DjangoSerializer(Serializer):
"""
Serializes into the existing django style.
"""
pk = ModelPKField()
model = ModelNameField()
fields = ModelFieldSetField()
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-developers/-/wm9YOnddZ3EJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.