orokusaki
orokusaki

Reputation: 57148

Django: Two Users with the same username

How can I extend Auth to allow for multiple users with the same username. In SAAS this is a need because two accounts might have a user called "owner" or something like that.

Upvotes: 2

Views: 2742

Answers (3)

Peter Rowell
Peter Rowell

Reputation: 17713

The problem with "user names" is that on a site with any decent size population Spencer's Lament (Henry Spencer @ U Toronto, Dept. of Zoology) comes into play: all of the good ones are taken. (He was referring to host names in the pre-DNS days, but it still applies.) The only "name" that is pretty much guaranteed to be unique is ... the email address. If you use that as Django's login identifier, then you can allow the user.username to be non-unique and used as a screen name. You still have to allow for people to change their email addresses, but they should still be unique across all users of a site.

We had to do this for a long-established site, as mentioned in this thread.

Upvotes: 3

Ludwik Trammer
Ludwik Trammer

Reputation: 25052

You could probably subclass the User model and write a custom authentication backend for your new model.

But first I would ask myself "do I REALLY need this?". Having multiple users with the same username sounds like a mess.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

You can't. Prefix the user name with the account name instead.

Upvotes: 1

Related Questions