I tried using the serialization as documented in http://docs.djangoproject.com/en/dev/topics/serialization/ and do something along the lines of
json = serializers.get_serializer('json')() json.serialize(o, ensure_ascii=False, fields=fields) "o" is a list of models that contain a reference to another model (foreign key), similar to what is described in [1]: ### start class MyModel(models.Model): category = models.ForeignKey(Category) ... class Category(models.Model) ... # name, and other attributes ### end I have observed a somewhat unintuitive behavior and would like to ask, whether this is intended, or I just did not see the right hint in the documentation: - If I pass "None" to the 'fields' argument in json.serialize, I receive the key of the referenced category in the serialized result along all other fields of MyModel and keys of other referenced models. - If I pass "['category']" to the 'fields' argument in json.serialize, the resulting fields are empty (in json: "fields": { }) After stepping through the code, I found out that this behavior is controlled in django.core.serializers.base.Serializer [2], and that I can show the referenced category, if I pass 'categ' instead of 'category' as field name; i.e. passing 'categ' in the fields argument results in the json "fields": { "category": <key> } Could anybody explain why this is the case? Did I miss something in the documentation, or should I have done something else to have the keys of the referenced models included in the serialized result? Thank you, Kariem [1] http://groups.google.com/group/django-users/browse_thread/thread/a3dd017a9ec0dadf [2] http://code.djangoproject.com/browser/django/tags/releases/1.0/django/core/serializers/base.py#L46 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---