Wrong documentation for changing Model formsets queryset
|Reported by:||Claude Paroz||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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)
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.
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.