Reputation: 11
I have the following code:
class ExampleModel(models.Model):
model_field = models.CharField()
class ExampleForm(forms.ModelForm):
non_model_field = forms.HiddenInput()
class Meta:
model = ExampleModel
fields = ('model_field', 'non_model_field',)
I get an exception:
FieldError
Unknown field(s) (non_model_field) specified for ExampleModel
How can I combine model field and non-model field in ModelForm?
Upvotes: 1
Views: 1157
Reputation: 13496
HiddenInput
is a widget class, not a form field class. Use something like this instead if you want a hidden input field:
forms.CharField(max_length=100, widget=forms.HiddenInput, required=False)
.
Upvotes: 3