#24295: Allow specifying form field types in a ModelForm's Meta
---------------------------------------+------------------------
               Reporter:  loic         |          Owner:  nobody
                   Type:  New feature  |         Status:  new
              Component:  Forms        |        Version:  master
               Severity:  Normal       |       Keywords:
           Triage Stage:  Unreviewed   |      Has patch:  0
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  0            |  Easy pickings:  0
                  UI/UX:  0            |
---------------------------------------+------------------------
 It's currently very fiddly to use a custom form field together with
 `ModelForm`.

 You can either set the field declaratively, which requires redefining all
 the attributes that would be automatically pulled from the model. It is
 not very DRY and quite error-prone, especially when it comes to `required`
 / `blank`. Or you can abuse `models.Field.formfield` by doing: `my_field =
 MyModel._meta.get_field('my_field').formfield(form_class=MyCustomField)`.

 This ticket proposes allowing:

 {{{
 class ArticleForm(ModelForm):
     class Meta:
         model = Article
         fields = ['pub_date', 'headline', 'content', 'reporter', 'slug']
         field_classes = {
             'slug': MySlugFormField,
         }
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24295>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.8d35ea17fed2903b28b6c10b84a8410c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to