I want to create a field in User model, the field should cotain 6 digits letter, it contains num or capital letters and also the field should be unique how can i achieve that
Should the field always have exactly 6 characters?
To clarify, the set of valid characters are 0-9, a-z, A-Z?
In general, to do this, you’ve got a couple different options.
The most performant and robust solution would be to create a custom field in the database, using a trigger to set the value when the object is being written to the database.
You can do this in Django, but you need to ensure that you have a table lock on the User model while you’re creating the value and checking it for uniqueness.
Another solution is to determine whether you really need to store that value in the database. Depending upon your application’s true requirements, you could create a transformation function that converts the autoincrement field into that representational format when it needs to be exposed to the outside world. (Again, that’s a decision that needs to be driven by the underlying requirements.)