Changeset 8941
- Timestamp:
- 09/03/08 15:23:18 (4 months ago)
- Files:
-
- django/trunk/docs/topics/serialization.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/topics/serialization.txt
r8506 r8941 58 58 ~~~~~~~~~~~~~~~~ 59 59 60 If you have a model that is defined using an `abstract base class`_, you don't 61 have to do anything special to serialize that model. Just call the serializer 62 on the object (or objects) that you want to serialize, and the output will be 63 a complete representation of the serialized object. 60 If you have a model that is defined using an :ref:`abstract base class 61 <abstract-base-classes>`, you don't have to do anything special to serialize 62 that model. Just call the serializer on the object (or objects) that you want to 63 serialize, and the output will be a complete representation of the serialized 64 object. 64 65 65 However, if you have a model that uses `multi-table inheritance`_, you also66 need to serialize all of the base classes for the model. This is because only 67 the fields that are locally defined on the model will be serialized. For 68 example, consider the following models::66 However, if you have a model that uses :ref:`multi-table inheritance 67 <multi-table-inheritance>`, you also need to serialize all of the base classes 68 for the model. This is because only the fields that are locally defined on the 69 model will be serialized. For example, consider the following models:: 69 70 70 class Place(models.Model):71 name = models.CharField(max_length=50)71 class Place(models.Model): 72 name = models.CharField(max_length=50) 72 73 73 class Restaurant(Place):74 serves_hot_dogs = models.BooleanField()74 class Restaurant(Place): 75 serves_hot_dogs = models.BooleanField() 75 76 76 77 If you only serialize the Restaurant model:: 77 78 78 data = serializers.serialize('xml', Restaurant.objects.all())79 data = serializers.serialize('xml', Restaurant.objects.all()) 79 80 80 81 the fields on the serialized output will only contain the `serves_hot_dogs` … … 84 85 serialize the Place models as well:: 85 86 86 all_objects = list(Restaurant.objects.all()) + list(Place.objects.all()) 87 data = serializers.serialize('xml', all_objects) 88 89 .. _abstract base class: http://www.djangoproject.com/documentation/model-api/#abstract-base-classes 90 .. _multi-table inheritance: http://www.djangoproject.com/documentation/model-api/#multi-table-inheritance 87 all_objects = list(Restaurant.objects.all()) + list(Place.objects.all()) 88 data = serializers.serialize('xml', all_objects) 91 89 92 90 Deserializing data
