Sunday, December 24, 2017

'Question' object has no attribute 'choice_text'

I've made anything by site tutorial, just repeat all steps and code. And when I wrote this:

 >>> from polls.models import Question, Choice
# Make sure our __str__() addition worked.  >>> Question.objects.all()  <QuerySet [<Question: What's up?>]>    # Django provides a rich database lookup API that's entirely driven by  # keyword arguments.  >>> Question.objects.filter(id=1)  <QuerySet [<Question: What's up?>]>  >>> Question.objects.filter(question_text__startswith='What')  <QuerySet [<Question: What's up?>]>    >>> from django.utils import timezone  >>> current_year = timezone.now().year  >>> Question.objects.get(pub_date__year=current_year)  <Question: What's up?>      >>> Question.objects.get(id=2)  Traceback (most recent call last):      ...  DoesNotExist: Question matching query does not exist.      >>> Question.objects.get(pk=1)  <Question: What's up?>    >>> q = Question.objects.get(pk=1)  >>> q.was_published_recently()  True    >>> q = Question.objects.get(pk=1)  >>> q.choice_set.all()

Im getting 'Question' object has no attribute 'choice_text'. 
But then I have got some magic solution! I define if Im writting only this:
>>>from polls.models import Choice, Question  >>>from django.utils import timezone    >>>q = Question.objects.get(pk=1)    >>>q.choice_set.all()  Out[4]: <QuerySet []>  
Then I dont have any problems, but I have done the same main steps then before(like in tutorial)! Sorry, but WTF is going on?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/33e82e65-b97a-46f9-be2c-38905fccc01a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment