Opened 6 years ago

Closed 5 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 6 years ago.
simple patch
ticket15315.patch (2.1 KB) - added by Will Hardy 6 years ago.
Updated the diff to the current trunk and added a test

Download all attachments as: .zip

Change History (12)

Changed 6 years ago by SardarNL

Attachment: models.py.diff added

simple patch

comment:1 Changed 6 years ago by Russell Keith-Magee

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 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:3 Changed 6 years ago by Will Hardy

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

Changed 6 years ago by Will Hardy

Attachment: ticket15315.patch added

Updated the diff to the current trunk and added a test

comment:4 Changed 6 years ago by Will Hardy

Needs tests: unset
Patch needs improvement: unset

comment:5 Changed 6 years ago by Will Hardy

Keywords: dceu2011 added

comment:6 Changed 6 years ago by Will Hardy

Owner: changed from Will Hardy to nobody
Status: assignednew

comment:7 Changed 6 years ago by Peter van Kampen

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

comment:8 Changed 5 years ago by AndrewIngram

Cc: AndrewIngram added

comment:9 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:10 Changed 5 years ago by Russell Keith-Magee

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