= Examples of serialized objects = Examples of data serialized with Django's [http://www.djangoproject.com/documentation/serialization/ serialization framework]. These all use the {{{Poll}}} example from [http://www.djangoproject.com/documentation/tutorial01/ tutorial 1]: {{{ #!python from django.db import models class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(maxlength=200) votes = models.IntegerField() }}} == XML == Though it's the most verbose, the XML format is considered somewhat canonical; all the other formats leave out some of the aspects of the XML format: {{{ #!xml What is your favorite color? 2007-06-06 11:23:42 What's your favorite web framework? 2007-06-06 11:24:17 1 Red 5 1 Blue 1 1 Pink... no, yellow... 3 2 Django 1000000 2 Rails 0 }}} == JSON == Though XML is canonical, [http://json.org JSON] is probably more useful for everyday use. There's not a lot of metadata, but if you know what the objects are, it works great. {{{ #!javascript [ { "pk": "1", "model": "se.poll", "fields": { "pub_date": "2007-06-06 11:23:42", "question": "What is your favorite color?" } }, { "pk": "2", "model": "se.poll", "fields": { "pub_date": "2007-06-06 11:24:17", "question": "What's your favorite web framework?" } }, { "pk": "1", "model": "se.choice", "fields": { "votes": 5, "poll": 1, "choice": "Red" } }, { "pk": "2", "model": "se.choice", "fields": { "votes": 1, "poll": 1, "choice": "Blue" } }, { "pk": "3", "model": "se.choice", "fields": { "votes": 3, "poll": 1, "choice": "Pink... no, yellow..." } }, { "pk": "4", "model": "se.choice", "fields": { "votes": 1000000, "poll": 2, "choice": "Django" } }, { "pk": "5", "model": "se.choice", "fields": { "votes": 0, "poll": 2, "choice": "Rails" } } ] }}} == YAML == Only available if [http://pyyaml.org PyYAML] is installed, this holds mostly the same data as the JSON serializer. However, YAML's probably easier to write by hand, so it's the most useful for fixtures. {{{ - model: se.poll pk: '1' fields: pub_date: !!timestamp '2007-06-06 11:23:42' question: 'What is your favorite color?' - model: se.poll pk: '2' fields: pub_date: !!timestamp '2007-06-06 11:24:17' question: 'What''s your favorite web framework?' - model: se.choice pk: '1' fields: choice: Red poll: 1 votes: 5 - model: se.choice pk: '2' fields: choice: Blue poll: 1 votes: 1 - model: se.choice pk: '3' fields: choice: 'Pink... no, yellow...' poll: 1 votes: 3 - model: se.choice pk: '4' fields: choice: Django poll: 2 votes: 1000000 - model: se.choice pk: '5' fields: choice: Rails poll: 2 votes: 0 }}}