#11735 closed (fixed)
Wrong documentation for changing Model formsets queryset
Reported by: | Claude Paroz | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the documentation, we can read that a Model Formset queryset can be changed with the following code:
class BaseAuthorFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): self.queryset = Author.objects.filter(name__startswith='O') super(BaseAuthorFormSet, self).__init__(*args, **kwargs)
See http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-the-queryset
This doesn't work. The problem is that in the __init__
function of BaseModelFormSet, the queryset is redefined from the queryset parameter which default to None.
See http://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L448
To make it work, the queryset should be added to the __init__
call as a keyword parameter. Or it might also be a bug in the __init__
function where it should test if self.queryset is not None before assigning to it. Either in docs, either in code, I think there is something to solve.
Attachments (1)
Change History (4)
by , 15 years ago
Attachment: | 11735.diff added |
---|
comment:1 by , 15 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
comment:2 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
switch the order of super/self.queryset lines