Hi all,

I'm looking for a way to override the default form field widget for some
fields of some model classes, at the project level.

Currently, we have to override all the model classes for that. That's
considerable as a hack, because we don't exactly want to "override the
default in every form class" but we want to "override the default".

The reason I need this at the project level is that really it's that unique
combination in INSTALLED_APPS that provides whatever widget I'd like to
override the default widget with, and how my project forms will look like.

For example, I'd like to have a RadioSelect for all relations to Foo model
and a django-redactor for all text fields named "html", my logic looks like:

        if getattr(db_field, 'rel', None) and db_field.rel.to == Foo:
            defaults['widget'] = forms.RadioSelect
        if db_field.model == Bar and 'html' in db_field.name:
            defaults['widget'] = redactor.RedactorWidget

A simple possibility is to add a setting which value would be a dotted path
to a callback, and basically change Field.formfield() so that it would use
this callback if it's defined. Here's an example patch: https://github.com/
django/django/pull/7723

Thanks for your feedback.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CALC3Kacn1k01wW824r%3Dp5Dn87%3DfkfNLDxCZz_68x83HaBsjmeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to