I’m using unique_together in the Meta Class in the model to prevent users to input their identical information into the database twice.
example:
class someModel(models.Model)
name=models.CharField(max_length=100)
address=models.CharField(max_length=100)
class Meta:
unique_together=("name","address")
When testing this out, I’ve noticed that it will return an error identical to the one returned when you leave a mandatory field empty. This is as a result of using {{field.errors}} in the template.
My question is how would you get it to give back a specific error (different than the mandatory field one) if this certain type of error occurs?
This seems to have been discussed already here: Django: How to override unique_together error message?
And just as a note:
The following section in Django docs go over custom form validation and error messages: https://docs.djangoproject.com/en/dev/ref/forms/validation/