1š
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:
request.user.commonuser.photo
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.
š¤PANDA Stack
0š
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
- Cross import in the same directory
- Django select_related, prefetch_related. How to read django_toolbar?
- 'HttpResponse' object has no attribute 'get_absolute_url'
- Django: Print out all choices for a models.Model class
- Overriding django's CheckboxSelectMultiple widget for Awesome Bootstrap Checkboxes
Source:stackexchange.com