[Answered ]-Django – Form – ForeignKey – Hidden – Default value

1πŸ‘

βœ…

You can override your form to always set the eval_sent_state field to the value you want in the save method, you should remove the field from the form fields though

class ClassSchoolTeacherForm(forms.ModelForm):

    class Meta:
        model = ClassSchool
        exclude = ['eval_sent_state']

    def save(self, *args, **kwargs):
        self.instance.eval_sent_state_id = 2
        return super().save(*args, **kwargs)

Leave a comment