Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#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)

14797.diff (2.5 KB ) - added by Gabriel Grant 14 years ago.

Download all attachments as: .zip

Change History (5)

by Gabriel Grant, 14 years ago

Attachment: 14797.diff added

comment:1 by Gabriel Grant, 14 years ago

Component: UncategorizedGeneric views
Has patch: set

comment:2 by Adam Vandenberg, 14 years ago

Things like "settings.LOGIN_URL" perhaps ought to be marked up as ":setting:LOGIN_URL"

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

(In [14809]) Fixed #14797 -- Corrected the handling of get_form_class() when a custom queryset has been defined, but a model hasn't. Thanks to Gabriel Grant for the report and patch.

comment:4 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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