#10874: ModelFormMetaclass does not provide easy way of extending
-----------------------------+------------------------------------
     Reporter:  wombat       |                    Owner:  nobody
         Type:  New feature  |                   Status:  new
    Component:  Forms        |                  Version:  1.0
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Accepted
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+------------------------------------

Comment (by Matt Westcott):

 For anyone looking for a way to extend ModelFormOptions with their own
 options, I found this recipe works well: https://github.com/wagtail
 /django-permissionedforms/blob/main/permissionedforms/forms.py

 There's a slight bit of ugliness in the implementation, in that
 ModelFormMetaclass builds a ModelFormOptions instance to do its own thing,
 which then gets thrown away and replaced with the custom ModelFormOptions
 subclass, meaning that the ModelFormOptions constructor ends up running
 for a second time. This could be avoided if ModelFormMetaclass were to
 look for an `options_class` attribute on either the target class (as per
 above) or itself (as per my implementation).

 (Even better, Django could move the 'collect options from an inner Meta
 class' logic into a mixin as I've done, so that the pattern of having
 various form mixin classes contribute their own options can happen with or
 without ModelForm. But given the lack of activity on this issue, that's
 probably too niche an interest to be worth the disruption :-) )

-- 
Ticket URL: <https://code.djangoproject.com/ticket/10874#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017f59d0d0ad-f0a24251-8835-401f-8e0d-1f57a0c2f9bb-000000%40eu-central-1.amazonses.com.

Reply via email to