9👍
✅
Only use specified fields:
class FirstModelForm(forms.ModelForm):
class Meta:
model = TheModel
fields = ('title',)
def clean_title(self....
It is common to use different ModelForms for a model in different views, when you need different features. So creating another form for the model that uses the same behaviour (say clean_<fieldname>
methods etc.) use:
class SecondModelForm(FirstModelForm):
class Meta:
model = TheModel
fields = ('title', 'description')
1👍
If you don’t want to update a field, remove it from the form via the Meta exclude
tuple:
class Meta:
exclude = ('title',)
- Django : Deduce duplicate key exception from IntegrityError
- Psycopg2.DataError: invalid input syntax for integer: "test" Getting error when moving code to test server
- Serializer validate function is not called DRF
Source:stackexchange.com