Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29325 closed Bug (invalid)

Django docs Polls App,Diferent queryset returns same object values but QuestionIndexViewTests works for one query and fails for other

Reported by: hgamit Owned by: nobody
Component: Generic views Version: 2.0
Severity: Normal Keywords: polls, model, tests
Cc: hgamit Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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.

views.py (Not Working: Added annotate(num = Count('choice')).filter(num__gt=1))

class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.annotate(num = Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5]

Error:

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: [] != ['']

Change History (3)

comment:1 by Tim Graham, 7 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

Please see TicketClosingReasons/UseSupportChannels for ways to get help.

comment:2 by hgamit, 7 years ago

Cc: hgamit added
Resolution: invalid
Status: closednew

@Tim Graham: I am really stuck around testcases and queryset. What is the solution for this issue? What do you mean by invalid? Do you need more info?

comment:3 by Simon Charette, 7 years ago

Resolution: invalid
Status: newclosed

Hello hgamit,

This ticket tracker should be used to keep track of Django bugs and feature requests and isn't a support channel per se.

The link Tim pointed you to contains reference to mailing lists and IRC channels where you should be able to find support for your issue.

Version 0, edited 7 years ago by Simon Charette (next)
Note: See TracTickets for help on using tickets.
Back to Top