Hi Djangoers,I am almost completing my first tutorial but got stuck at the last point. So I am assigning Choice object to 'c',c = p.choice_set.filter(choice_text__startswith='Just') And I am getting this output when I check 'c'[<Choice: Just Hacking again>]And I am also getting the right output for 'p'<Poll: WASSUP!!!!>But when I am executing,c.pollThis is my output,Traceback (most recent call last):File "<console>", line 1, in <module>AttributeError: 'QuerySet' object has no attribute 'poll'Not sure where I am going wrong?--
Thanks & RegardsSmaran Harihar
You're not assigning a Choice object to `c`. You're assigning a queryset (basically, a list) of one Choice objects to c - hence the square brackets when you print it. As the documentation explains, `filter` *always* returns a queryset, even if only one object matches.
You can do c[0] to get the Choice object, or use `get()` instead of `filter()` (although note that will raise an exception if zero or > 1 objects match).
--
DR.
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/p-sNQq_41PUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment