#14797 closed (fixed)
ModelFormMixin's get_form_class() logic broken; fails with custom get_queryset() method
| Reported by: | Gabriel Grant | Owned by: | Gabriel Grant |
|---|---|---|---|
| Component: | Generic views | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In the ModelFormMixin's get_form_class(), the logic in the else clause is broken:
- if self.model is set, it uses that instead of the queryset (whereas according to the docs "the value of SingleObjectMixin.queryset supersedes the value provided for SingleObjectMixin.model")
- if self.model is not set, it uses self.queryset.model, ignoring the get_queryset() method
The attached patch fixes both issues
As an aside, perhaps SingleObjectMixin should have a get_model() method that encapsulates and/or shortcuts this logic? On the one hand, using get_queryset().model isn't particularly intuitive, but on the other hand having get_model() may be getting a little too fine-grained.
Attachments (1)
Change History (5)
by , 15 years ago
| Attachment: | 14797.diff added |
|---|
comment:1 by , 15 years ago
| Component: | Uncategorized → Generic views |
|---|---|
| Has patch: | set |
comment:2 by , 15 years ago
comment:3 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Things like "settings.LOGIN_URL" perhaps ought to be marked up as ":setting:
LOGIN_URL"