#9897: Misleading model formsets docs
-------------------+--------------------------------------------------------
Reporter: sorl | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
-------------------+--------------------------------------------------------
The following example could easily generate an invalid queryset:
{{{
from django.forms.models import BaseModelFormSet
class BaseAuthorFormSet(BaseModelFormSet):
def get_queryset(self):
return super(BaseAuthorFormSet,
self).get_queryset().filter(name__startswith='O')
}}}
Calling super method will slice the queryset if max_num is set, and thus
filter on the slice will be invalid. The following would be more correct:
{{{
from django.forms.models import BaseModelFormSet
class BaseAuthorFormSet(BaseModelFormSet):
def get_queryset(self):
if not hasattr(self, '_queryset'):
if self.queryset is not None:
qs = self.queryset
else:
qs =
self.model._default_manager.get_query_set().filter(name__startswith='O')
if self.max_num > 0:
self._queryset = qs[:self.max_num]
else:
self._queryset = qs
return self._queryset
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/9897>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---