I am using crispy forms for my Django project, and in one of the forms I am using, there is a field that needs to be unique when entered, but it should be possible to leave it blank as well.
For my student database project, each student has a student_id that is set as a primary key, and each student should also have an anonymous_id that will be added at a later point in the year. This exam ID should be unique to stop the admin from entering it for the wrong student. Very simplified, the model looks like this:
class Student(models.Model):
student_id = models.CharField(primary_key=True)
anonymous_id = models.CharField(null=True, blank=True, unique=True, default=None)
...
and the form just lists both fields in a tab. Without Crispy Forms, it was no problem to enter students with a blank field for "anonymous_id", but now it complains with the second student ("Student with this Anonymous ID already exists.") - presumaby because there is already one who has "None" as his ID.
Is there anything I can do to turn off the validation for None only or will I have to remove the unique constraint?
Thanks, Tobi