2

With this explanation of implementing a custom user model in django there is the inclusion of error_messages{...} dictionary.

Where does 'unique' come from? Where can I find a comprehensive list of the possible options?

I have looked at the documentation for built-in field classes here and I have looked in the appropriate fields.py file on github which says EmailField inherits from CharField, which in turn inherits from base Field class. None of these mention 'unique' as a possible key in the dictionary so I'm really confused as to why you can define it.

pilky01
  • 132
  • 8

1 Answers1

2

In the Django documentation on the model fields, it specifies that;

Error message keys include null, blank, invalid, invalid_choice, unique, and unique_for_date. Additional error message keys are specified for each field in the Field types section below.

For some fields, there are extra error messages that can be specified, in that case it is mentioned for that field.

Not all error messages are applicable for all fields. For example if you have a field where you do not pass choices=… [Django-doc], it will of course never have to specify invalid_choice as parameter. The same holds for unique for a non-unique field, etc.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • Thank you for the prompt response. The info was there it's just a case of piecing the bits together. – pilky01 Aug 03 '21 at 20:18