Re: Polls tutorial receive object not object representation
> 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? It should be said that yes, that is normal. p.choice_set.all() is a list of Choice objects, not a list of strings attributes for each object. You're right that it's not a very readable result, which is why the __unicode__ method exists to add a more user-friendly representation of that object for console/Django admin display. Still, don't lose sight of the fact that p.choice_set.all() is actually always returning a collection of Choice objects. -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Polls tutorial receive object not object representation
On Jan 27, 2013 10:58 PM, "Sayth Renshaw"wrote: > > 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? That happens because you seem to hsve missed or decided to skip the instructions located right above the interactive section you are at: The one about adding __unicode__ methods to the models and saving the models.py file. -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Polls tutorial receive object not object representation
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) > > >>> p.choice_set.create(choice_text='The sky', votes=0) > > >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0) > > # Choice objects have API access to their related Poll objects. > >>> c.poll > > > # And vice versa: Poll objects get access to Choice objects. > >>> p.choice_set.all() > [, , ] > 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]: > > In [16]: p.choice_set.all() > Out[16]: [, , object>, 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 rahmc...@radio1190.org -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Polls tutorial receive object not object representation
On Jan 27, 2013 5:58 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) > > >>> p.choice_set.create(choice_text='The sky', votes=0) > > >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0) > > # Choice objects have API access to their related Poll objects. > >>> c.poll > > > # And vice versa: Poll objects get access to Choice objects. > >>> p.choice_set.all() > [, , ] > > 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]: > > In [16]: p.choice_set.all() > Out[16]: [, , , ject>] You probably need a p.save() after creating the choices to actually place them in the database...otherwise I can see why the ORM is confused since choices_set causes a database hit and you are expecting objects that don't technically exist yet... > Thanks > > Sayth > > -- > 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 django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Polls tutorial receive object not object representation
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)>>> p.choice_set.create(choice_text='The sky', votes=0)>>> c = p.choice_set.create(choice_text='Just hacking again', votes=0) # Choice objects have API access to their related Poll objects.>>> c.poll # And vice versa: Poll objects get access to Choice objects.>>> p.choice_set.all()[, , ] 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]: In [16]: p.choice_set.all() Out[16]: [, , , ] Thanks Sayth -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.