I’m working on a project in django which calls for having separate groups of users in their own username namespace.
So for example, I might have multiple “organizations”, and username should only have to be unique within that organization.
I know I can do this by using another model that contains a username/organization id, but that still leaves this useless (and required) field on the defualt django auth User that I would have to populate with something.
I’ve already written by own auth backend that authenticates a user against LDAP. However, as I mentioned before, I am still stuck with the problem of how to populate / ignore the username field on the default django user.
Is there a way to drop the uniqueness constraint for the username for Django auth users?
I’m not sure if this is exactly what you’re looking for, but I think you could use a hack similar to what is in this answer.
The following code works, as long as it is in a place that gets executed when Django loads your models.
Note that this won’t change the database unique constraint on the
auth_usertable if it has been already been created. Therefore you need to make this change before you run syncdb. Alternatively, if you don’t want to recreate yourauth_usertable, you could make this change and then manually alter the database table to remove the constraint.