Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd like to expand on the solution by @thornomad. </p> <p>Extending Django's User class directly can cause all kinds of trouble with the internal django.auth mechanisms. What I've done in a similar situation is precisely what @thornomad suggests - I made my own UserProfile model linked one-to-one with the Django User model, in which I held additional user data and from which I inherited models for different types of users.</p> <p>Something to fit what you described:</p> <pre><code>class UserProfile(models.Model): user = models.OneToOneField(User, blank=True, related_name='profile') class Meta: abstract = True class PositionHolderUserProfile(UserProfile): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) landline = models.CharField(blank=True, max_length=20) mobile = models.CharField(blank=True, max_length=20) created_by = models.ForeignKey(PositionHolderUserProfile, editable=False, blank=True, related_name="created_users") modified_by = models.ForeignKey(PositionHolderUserProfile, editable=False, blank=True, related_name="modified_users") class Principal(PositionHolderUserProfile): branchoffice = models.ForeignKey(BranchOffice) class Administrator(PositionHolderUserProfile): superior = models.ForeignKey(Principal, related_name="subordinates") province = models.ForeignKey(Province) class Coordinator(PositionHolderUserProfile): superior = models.ForeignKey(Administrator, related_name="subordinates") class Company(UserProfile): name = models.CharField(max_length=50) class Product(models.Model): name = models.CharField(max_length=50) produced_by = models.ForeignKey(Company) class Buyer(UserProfile): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) products_bought = models.ManyToManyField(Product) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload