[Answered ]-Django – Allow duplicate user's emails in the grand User model, but unique in its extended models?

1👍

What you have implemented so far is almost Djangos implementation of multi-table inheritance. You need to move the username to the extended class (and actually extend it in the code not just conceptually).

You can read up on how this is implemented in the documentation.

Your code should look somewhat like this:

class Customer(User):
    username = models.CharField(db_index=True, max_length=255, unique=True)

    objects = UserManager()

class Technician(User):
    username = models.CharField(db_index=True, max_length=255, unique=True)

Under the hood django implements a one to one field on these models which provide some neat syntax simplifications, but fair warning this can create some challenges in further implementation.

As to what the best solutions is, there is none, there’s only one that fits your needs best. It’s best not to think too far ahead but face challenges as they come. Who knows you might end up prefering the two table systems better. On the other hand the user superclass sharing some properties may prove useful.

For more options look at this

👤Blye

Leave a comment