Django auth has username and first_name fields. But username has field option unique=True. This prevents a user from giving first_name same as username when registering and raises IntegrityError. How to bypass this and also keeping username unique? ie. no two users should have the same username. But username can be same as first_name. And two users can have same first_name, last_name.
Django auth has username and first_name fields. But username has field option unique=True. This
Share
You cannot achieve that. If you want to have the same value in fields first_name and username and one of them is not unique, the other one also cannot be unique.
As far as I understand what you’re doing here, you just want to display first_name instead of username – to achieve that just use
{{ user.first_name }}instead of just{{ user }}. If you need to store some additional information about users you can also define Profiles where you can implement your own__str__method.