[Fixed]-Getting a 'This field is required` error when updating a model instance

1๐Ÿ‘

โœ…

If you only want some of the fields to be editable, you should set fields in your model form. If you use PostForm in another view and cannot edit fields, then create a new form.

class EditPostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ['content']

You can subclass PostForm if you prefer:

class EditPostForm(PostForm):
    class Meta(PostForm.Meta):
        fields = ['content']

Then update your edit view to use EditPostForm instead of PostForm.

๐Ÿ‘คAlasdair

Leave a comment