[Django]-How to save a field after commit=False with model Form in Django?



A ModelForm will by default include and validate all fields of the model. If you always assign the alias value yourself in the view, then you don’t need the alias field in the form and you can just exclude it:

class BookForm(ModelForm):

    class Meta:
        model = Book
        fields = ('name', 'description')
        # NOTE: you can also use excludes, but many consider it a bad practice

As always, Django docs can tell you more about it.



You’re trying to save the model without an alias first. You need to allow blank values before you can do that. The recommended approach would be using blank:

alias = models.CharField(max_length=100, blank=True)

Leave a comment