Hi,
I am quite new to django, so the following question may have an
obvious answer, but I could not find it.
I have defined the model from the django tutorial, Poll and Choice:
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
I can see all the choices related to a poll though its attribute:
<poll_instance>.choice_set.
My question is, what method or attribute is there on poll that tells
me that it has a model attribute 'choice_set' ?
My specific problem is that if I use the django serialization
framework, when I give it a poll it will only print the 'question' and
'pub_date' fields, but not 'choice_set'. I guess this is because
there is no mention of the set in Poll._meta.local_fields, but there
doesn't appear to be an option for serializing nested model sets:
serializers.serialize('xml', Poll.objects.all()) produces:
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="1" model="polls.poll">
<field type="CharField" name="question">What's up?</field>
<field type="DateTimeField" name="pub_date">2008-10-08
11:21:12</field>
</object>
</django-objects>
I know that if it included the choice set directly then the cycle
would cause an infinite loop, but I would write my own serializer that
would only output a reference to the other entities.
Any help is appreciated!
Thanks,
John.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
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-users?hl=en
-~----------~----~----~----~------~----~------~--~---