| | 142 | # Tests for Trac item #3466 - 'fields' option not working for json serializer. |
|---|
| | 143 | # Serialize and deserialize passing a single field name. |
|---|
| | 144 | >>> json = serializers.serialize("json", AuthorProfile.objects.all(), fields = "date_of_birth") |
|---|
| | 145 | >>> json |
|---|
| | 146 | '[{"pk": "1", "model": "serializers.authorprofile", "fields": {"date_of_birth": "1970-01-01"}}]' |
|---|
| | 147 | |
|---|
| | 148 | >>> for obj in serializers.deserialize("json", json): |
|---|
| | 149 | ... print obj |
|---|
| | 150 | <DeserializedObject: Profile of Joe> |
|---|
| | 151 | |
|---|
| | 152 | # Serialize and deserialize passing multiple field names. |
|---|
| | 153 | >>> json = serializers.serialize("json", Article.objects.all(), fields = ["author", "headline"]) |
|---|
| | 154 | >>> for obj in serializers.deserialize("json", json): |
|---|
| | 155 | ... print obj |
|---|
| | 156 | <DeserializedObject: Just kidding; I love TV poker> |
|---|
| | 157 | <DeserializedObject: Time to reform copyright> |
|---|
| | 158 | |
|---|