In my django project I have 2 variations of users. One subclasses User class from django.auth and second uses almost the same fields but is not a real user (so it doesn't inherit from User). Is there a way to create a FieldUser class (that stores fields only) and for RealUser subclass both FieldUser and User, but for FakeUser subclass only FieldUser ?
Asked
Active
Viewed 2,405 times
1 Answers
4
sure, I've used multiple inheritance in django models, it works fine.
sounds like you want to setup an abstract class for FieldUser:
class FieldUser(models.Model):
field1 = models.IntegerField()
field2 = models.CharField() #etc
class Meta:
abstract=True #abstract class does not create a db table
class RealUser(FieldUser, auth.User):
pass #abstract nature is not inherited, will create its own table to go with the user table
class FakeUser(FieldUser):
pass #again, will create its own table

hwjp
- 15,359
- 7
- 71
- 70
-
superb ! That's what I was trying to achieve ! – crivateos Jun 23 '10 at 20:46
-
and some docs with that: https://docs.djangoproject.com/en/1.8/topics/db/models/#multiple-inheritance – elad silver May 31 '15 at 09:18