Opened 14 years ago

Closed 13 years ago

#15315 closed New feature (fixed)

modelform_factory should accept widgets argument

Reported by: SardarNL Owned by: nobody
Component: Forms Version: 1.2
Severity: Normal Keywords: dceu2011
Cc: AndrewIngram 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

Since Django 1.2 model forms can override widgets by specifying 'widgets' attribute in Meta, similar to 'fields' or 'exclude'. The modelform_factory doesn't accept widgets, so the only way to specify it is by defining a new parent ModelForm with Meta and giving it as 'form' argument. This is more complex than it needs to be.

The fix is to add new keyword argument widgets=None and add:

if widgets is not None:
        attrs['widgets'] = widgets

right after similar if for 'exclude'. This will add 'widgets' attribute to dynamically created Meta.

Attachments (2)

models.py.diff (1.1 KB ) - added by SardarNL 14 years ago.
simple patch
ticket15315.patch (2.1 KB ) - added by Will Hardy 14 years ago.
Updated the diff to the current trunk and added a test

Download all attachments as: .zip

Change History (12)

by SardarNL, 14 years ago

Attachment: models.py.diff added

simple patch

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

milestone: 1.3
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Three points:

  • This is a new feature, so it can't be on the 1.3 milestone
  • Please use unified diffs (i.e., the format generated by svn diff), rather than context diffs
  • Any patch for a new feature requires tests.

comment:2 by Łukasz Rekucki, 14 years ago

Severity: Normal
Type: New feature

comment:3 by Will Hardy, 14 years ago

Easy pickings: unset
Owner: changed from nobody to Will Hardy
Status: newassigned
UI/UX: unset

by Will Hardy, 14 years ago

Attachment: ticket15315.patch added

Updated the diff to the current trunk and added a test

comment:4 by Will Hardy, 14 years ago

Needs tests: unset
Patch needs improvement: unset

comment:5 by Will Hardy, 14 years ago

Keywords: dceu2011 added

comment:6 by Will Hardy, 14 years ago

Owner: changed from Will Hardy to nobody
Status: assignednew

comment:7 by Peter van Kampen, 14 years ago

This patch should probably also update the docs(tring) if/when #10239 is applied?

comment:8 by AndrewIngram, 13 years ago

Cc: AndrewIngram added

comment:9 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:10 by Russell Keith-Magee, 13 years ago

Resolution: fixed
Status: newclosed

In [16659]:

Fixed #15315 -- Added support for the 'widget' argument to modelform_factory. Thanks to SardarNL and Will Hardy for the patch.

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