Check if record exists in model

Ok, this is clearing up the picture quite a bit.

<input type="text" class="form-control" id="project-name" value="{{ project.project_name }}" required readonly>

There’s a fundamental issue with having this as a field in your form. The fact that it’s there as a form field is going to cause problems. Even though you’ve got it marked as readonly, the problems still exist. (Someone could use their browser’s developer tools and go in and change the value regardless.)

Steps to correct this:

  • Remove the project_name field from the Form class Meta. (Yes, that means replacing the __all__ with the list of fields you want editable.)

  • Either:

    • Change the attribute of this field from readonly to disabled
    • Change this from an input field to just a block of text

(And yes, seeing this explains now why having the to_field attribute on the model allowed this form to be considered “valid”, despite the fact that it wasn’t going to work.)