Changes between Initial Version and Version 1 of Ticket #29325
- Timestamp:
- Apr 13, 2018, 7:19:53 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #29325
- Property Resolution → invalid
- Property Status new → closed
-
Ticket #29325 – Description
initial v1 1 1 In polls application I added annotation to check one to many relationship between Question and Choice models such that, Index only return questions with more than one choices to be displayed but my testcase fails all the time with annotation where both query returns same data. 2 2 3 views.py (Not Working: Added annotate(num = Count('choice')).filter(num__gt=1)) 3 views.py (Not Working: Added `annotate(num = Count('choice')).filter(num__gt=1))` 4 {{{ 5 class IndexView(generic.ListView): 6 template_name = 'polls/index.html' 7 context_object_name = 'latest_question_list' 4 8 5 class IndexView(generic.ListView): 6 template_name = 'polls/index.html' 7 context_object_name = 'latest_question_list' 8 9 def get_queryset(self): 10 """Return the last five published questions.""" 11 return Question.objects.annotate(num = Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5] 12 9 def get_queryset(self): 10 """Return the last five published questions.""" 11 return Question.objects.annotate(num = Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5] 12 }}} 13 13 Error: 14 15 Traceback (most recent call last): File "C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in test_past_question [''] File "C:\ProgramData\Anaconda3\envs\django\lib\site-packages\django\test\testcases.py", line 940, in assertQuerysetEqual return self.assertEqual(list(items), values, msg=msg) AssertionError: Lists differ: [] != [''] 14 {{{ 15 Traceback (most recent call last): File "C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in test_past_question [''] 16 File "C:\ProgramData\Anaconda3\envs\django\lib\site-packages\django\test\testcases.py", line 940, in assertQuerysetEqual return self.assertEqual(list(items), values, msg=msg) AssertionError: Lists differ: [] != [''] 17 }}}