[Fixed]-Extending Django User with subclasses


I’m on mobile, so I can’t test this, but…

I would set a “related_name” on your CommonUser.user field called “commonuser”. Then you can just use:


like you are already.

I think the issue is that you are referencing a Django User object to reference a backwards relationship without the proper name.


First off, I think this model is more of a Profile than User. If you don’t mind using 1.9 (and postgres) then this is a perfect usecase for a JSON field. You can filter with regular lookups and don’t need to specify each type. That way you can also extend the user model in such a way that a user can fulfill many roles at once. The other thing I thought of was linking it the other way around:

class UserProfile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    # ...

class Installer(models.Model):
    profile = models.ForeignKey(UserProfile, related_name='installer')
    #HERE: Specific properties for Installer Companies

class Administration(models.Model):
    profile = models.ForeignKey(UserProfile, related_name='admin')
    #HERE: Specific properties for Administration

class Client(models.Model):
    profile = models.ForeignKey(UserProfile, related_name='client')
    #HERE: Specific properties for Clients

Leave a comment