Changes between Initial Version and Version 1 of Ticket #29325


Ignore:
Timestamp:
Apr 13, 2018, 7:19:53 PM (6 years ago)
Author:
Tim Graham
Comment:

Please see TicketClosingReasons/UseSupportChannels for ways to get help.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29325

    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #29325 – Description

    initial v1  
    11In 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.
    22
    3 views.py (Not Working: Added annotate(num = Count('choice')).filter(num__gt=1))
     3views.py (Not Working: Added `annotate(num = Count('choice')).filter(num__gt=1))`
     4{{{
     5class IndexView(generic.ListView):
     6    template_name = 'polls/index.html'
     7    context_object_name = 'latest_question_list'
    48
    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}}}
    1313Error:
    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{{{
     15Traceback (most recent call last): File "C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in test_past_question ['']
     16File "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}}}
Back to Top