Whoops, I referenced the docs for the Model save() function, not the
ModelForm save() function. The signatures should be updated:
def save(self, commit=True):
rather than:
def save(self, *args, **kwargs):
The super() call would also need to be modified accordingly:
def save(self, commit=True):
I understand that the the 'extra fields' are not part of the main model.
However, without either providing a save() method definition somewhere,
those fields will never be saved. Take the example I posted previously:
class ModelFormMixin(forms.ModelForm):
extra_field_1 = forms.CharField(requir
Thanks James.
Maybe I did not well mention that the extra fields are not fields of the
Model. I do not want Django to try to save them in the model.
Also, I did not make FormA inherits from forms.ModelForm because there is
no Model to define and I want to use these extra fields with any type of
Maybe I did not well mention that the extra fields are not fields of the
Model.
Also, I did not make FormA inherits from forms.ModelForm because there is
no Model to define and I w
Le samedi 15 novembre 2014 02:41:11 UTC-6, James Schneider a écrit :
>
> "Why does the following not give a final
"Why does the following not give a final model form with 3 fields?
The two extra fields are not available. If I move them directly into the
model form, it works but I wanted to declare these fields in a separate
form because I plan on reusing them in several forms.
Is there a way to do that?"
I al
I think you're overcomplicating things. Check this out:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#form-inheritance
http://chriskief.com/2013/06/30/django-form-inheritance/
Try this:
class ModelFormExtraFields(forms.ModelForm):
extra_field_1 = forms.CharField(required=Fal
Thanks for your response James.
I am not well familiar with the metaclasses, I do not really see how to do
it.
What do you think of adding the fields in the init this way?
extra_fields = {'extra1': forms.CharField(required=False), 'extra2':
forms.CharField(required=False)}
class ModelFormA(forms
Modify your Meta class to include the extra fields on the model form. The
Meta classes are not inherited.
You may also need to override the save() method on your model form to
actually save the contents of those extra fields in the inherited form.
-James
On Nov 13, 2014 6:32 PM, "Michael" wrote:
Hi,
Why does the following not give a final model form with 3 fields?
The two extra fields are not available. If I move them directly into the
model form, it works but I wanted to declare these fields in a separate
form because I plan on reusing them in several forms.
Is there a way to do that?
9 matches
Mail list logo