On Jan 27, 2013, at 6:53 PM, Sayth Renshaw wrote:

> Hi
> 
> Just seeking a little clarification.
> 
> In the Polls tutorial we get this section.
> 
> >>> p = Poll.objects.get(pk=1)
> 
> # Display any choices from the related object set -- none so far.
> >>> p.choice_set.all()
> []
> 
> # Create three choices.
> >>> p.choice_set.create(choice_text='Not much', votes=0)
> <Choice: Not much>
> >>> p.choice_set.create(choice_text='The sky', votes=0)
> <Choice: The sky>
> >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0)
> 
> # Choice objects have API access to their related Poll objects.
> >>> c.poll
> <Poll: What's up?>
> 
> # And vice versa: Poll objects get access to Choice objects.
> >>> p.choice_set.all()
> [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]

> Now the only thing is that when I call p.choice_set.all() I don't get the 
> representation 'The sky' or 'Just Hacking again' . I receive choice object 
> itself. Is this normal?

> In [14]: c = p.choice_set.create(choice_text='Just Hacking again', votes=0)
> 
> In [15]: c.poll
> Out[15]: <Poll: What's up?>
> 
> In [16]: p.choice_set.all()
> Out[16]: [<Choice: Choice object>, <Choice: Choice object>, <Choice: Choice 
> object>, <Choice: Choice ob
> ject>]
> 
> Thanks 
> Sayth

Did you add an __unicode__ method to Choice class? That's how you get the 
pretty representations of objects. 
https://docs.djangoproject.com/en/1.4/intro/tutorial01/#playing-with-the-api

Peter of the Norse
[email protected]



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to