On Fri, Jun 4, 2021 at 11:54 PM Carlton Gibson <carlton.gib...@gmail.com> wrote: > I'm sympathetic to the suggestion here, but wary of expanding the Forms API, > which already has a number of different ways of holding it. > > > ...to impose uniform custom widget attributes and error messages across a > > bunch of ModelForms... > > My initial query is, would not defining `field_classes`[1] on, say, a base > form class for your project be a/the way to go here?
Without getting too far off into details, the basic issue is I have an app where there are a lot of ModelForms, and for certain model field types we want the form field to always get set up in a way that differs from Django's defaults (think of, say, always wanting a particular custom widget setup, or custom error messages, for a particular model field type). It's a thing that you *can* do by writing out overrides or re-declarations of the relevant fields on each form. But when you have dozens of forms and there's no consistent pattern to the naming of the fields you want to override, it gets really tedious to write out and maintain all those overrides. Which is why the code uses formfield_callback -- that is Django's customization hook for this type of "every instance of model field of this type, output a form field of this type" stuff. And it's already crept into documented API, to some extent, because the model form/formset factories document it as a parameter. So I'd just like for it to become proper fully-documented API with consistent behavior (since right now its behavior and effect varies according to how you specify it and how you construct your forms). (the only other real alternative right now is to go write a custom model field subclass and implement formfield() on it, then go migrate a bunch of models to use the new custom field instead of the default Django one. But it feels odd and wrong to me that form-only behavior would need to be overridden in the model rather than in the form) -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAL13Cg8thHw7Sj-8KoAzU4J0QgWo9EXMNXDw1jkt2QtZBvDf5g%40mail.gmail.com.