Opened 4 years ago

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

Download all attachments as: .zip

Change History (12)

Changed 4 years ago by SardarNL

simple patch

comment:1 Changed 4 years ago by russellm

  • milestone 1.3 deleted
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by willhardy

  • Easy pickings unset
  • Owner changed from nobody to willhardy
  • Status changed from new to assigned
  • UI/UX unset

Changed 4 years ago by willhardy

Updated the diff to the current trunk and added a test

comment:4 Changed 4 years ago by willhardy

  • Needs tests unset
  • Patch needs improvement unset

comment:5 Changed 4 years ago by willhardy

  • Keywords dceu2011 added

comment:6 Changed 4 years ago by willhardy

  • Owner changed from willhardy to nobody
  • Status changed from assigned to new

comment:7 Changed 4 years ago by pterk

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

comment:8 Changed 4 years ago by AndrewIngram

  • Cc AndrewIngram added

comment:9 Changed 4 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:10 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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