17👍
✅
Create a model with OneToOneField
to User
and related_name
.
E. g.:
class Firm(models.Model):
user = models.OneToOneField(User, related_name='firm')
# other fields
class External(models.Model):
user = models.OneToOneField(User, related_name='external')
# other fields
Then you can check the existance of this attributes in user
(if hasattr(request.user, 'firm')
) and return proper instance. I’d put it in custom middleware, which would set request.user_profile
for example.
Source:stackexchange.com