Changes between Initial Version and Version 1 of Ticket #27510
- Timestamp:
- Nov 21, 2016, 5:13:15 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27510
- Property Easy pickings unset
-
Ticket #27510 – Description
initial v1 1 1 Hello, 2 I think that only being able to pass the `fields` keyword argument in `ModelFormMixin.get_form_class ` is very limiting.2 I think that only being able to pass the `fields` keyword argument in `ModelFormMixin.get_form_class()` is very limiting. 3 3 4 Being able to specify the fields greatly reduces boilerplate and is an awesome feature, but the moment you want anything more then you have to create a ModelForm. Tim Gra yham argues in [https://code.djangoproject.com/ticket/24589] that "I don't think the possibility of saving a few lines of user code justifies the complexity of reimplementing the parameters to modelform_factory() as CBV parameters and methods.", however I don't believe that it adds any significant complexity and sorely missing in some circumstances, and it already exists for standard forms via the `get_form_kwargs` functionality.4 Being able to specify the fields greatly reduces boilerplate and is an awesome feature, but the moment you want anything more then you have to create a ModelForm. Tim Graham argues in #24589 that "I don't think the possibility of saving a few lines of user code justifies the complexity of reimplementing the parameters to `modelform_factory()` as CBV parameters and methods.", however I don't believe that it adds any significant complexity and sorely missing in some circumstances, and it already exists for standard forms via the `get_form_kwargs()` functionality. 5 5 6 The main use case for this feature would be adding custom widgets to model forms. For example, if you have a view that can return two different sets of fields based on the viewing user and you require one of them to have a custom widget for this field then you would have to define two separate ModelForms, one with each set of fields. If you then want to add another set of fields for a user type then you need yet another ModelForm. This gets tiring very fast.6 The main use case for this feature would be adding custom widgets to model forms. For example, if you have a view that can return two different sets of fields based on the viewing user and you require one of them to have a custom widget for this field then you would have to define two separate model forms, one with each set of fields. If you then want to add another set of fields for a user type then you need yet another model form. This gets tiring very fast. 7 7 8 What is wrong with simply having a `get_modelform_kwargs ` functionthat by default returns `{"fields": self.fields}`? The implementation would be very short.8 What is wrong with simply having a `get_modelform_kwargs()` method that by default returns `{"fields": self.fields}`? The implementation would be very short. 9 9 10 10 I'm willing to work on a patch if others agree this is a good idea.