Re: Allow usage of widgets in generic class-based views?

2018-12-05 Thread Alasdair Nicol
This is getting into django-users territory, but I wanted to point out that it's often better to leave out the field instead of using a hidden input. You can then override the form_valid() method, and set the value before the form is saved. class PatientCreate(LoginRequiredMixin, UserOrgReq

Re: Allow usage of widgets in generic class-based views?

2018-12-05 Thread Dan Frankowski
Ah, I see. It looks like I can use modelform_factory. So: class PatientCreate(LoginRequiredMixin, UserOrgRequiredMixin, CreateView): model = models.Patient fields = ['name', 'caregiver_name', 'sex', 'birth_date', 'residence', 'country'] becomes from django.forms.models imp

Re: Allow usage of widgets in generic class-based views?

2018-12-05 Thread Carlton Gibson
I'd be pretty sceptical about any extra API here. Even an extra hook seems a bit much. def get_form_class(self): base_form = super().get_form_class() return modelform_factory(self.model, base_form, widgets=...) Job done, no? (This assuming that "Just declare your form class normally"

Re: Allow usage of widgets in generic class-based views?

2018-12-04 Thread charettes
I agree with Tim that this is a slippery slope. Maybe that adding a ModelFormMixin.get_form_class_options() that returns a {'fields': self.fields} dict by default and is passed to modelform_factory(**kwargs) in get_form_class() would be a good compromise? Best, Simon Le mardi 4 décembre 2018 1

Re: Allow usage of widgets in generic class-based views?

2018-12-04 Thread Tim Graham
What I meant is that modelform_factory() also has these parameters: localized_fields is a list of names of fields which should be localized. labels is a dictionary of model field names mapped to a label. help_texts is a dictionary of model field names mapped to a help text. error_messages is a

Allow usage of widgets in generic class-based views?

2018-12-04 Thread Dan F
https://code.djangoproject.com/ticket/24589 This ticket has a patch to pass through the "widgets" argument for generic class-based views. It was closed with "won't fix" with this comment: "*I don't think the possibility of saving a few lines of user code justifies the complexity of reimplement