Opened 13 years ago

Closed 13 years ago

#18066 closed Bug (needsinfo)

ModelChoiceIterator reports incorrect length

Reported by: Berislav Lopac Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On line 899 of django/forms/models.py, the __len__ method returns the length of self.queryset, which always return as one -- instead, shouldn't it return the length of self.queryset.all()?

I have tried to get {% my_fk_field.choices|length %} and it kept returning as 1 -- only when I put {% my_fk_field.choices.queryset.all|length %} I got the correct length. I might be mistaken, but this looks like a bug to me...

Change History (1)

comment:1 by Claude Paroz, 13 years ago

Resolution: needsinfo
Status: newclosed

I cannot reproduce the error, we will need some more code to see what's wrong here. Generally, calling len() on a queryset is a totally valid method to get the result length.

Note: See TracTickets for help on using tickets.
Back to Top