-
class Website(models.Model):
name = models.CharField(max_length=200)
provider_id = models.CharField(max_length=20, default="", blank=True)
account = models.ForeignKey(Account, on_delete=models.CASCADE, default=None, null=True) at the views.py i want to be able to fetch all the website that belongs to the Account that itself is associated by the request.user via AccountUser
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Sorry for not seeing this earlier! A user filter here would need to check against the account users, e.g. instead of Website.objects.filter(account=request.user.) You'd check against the linking model, the OrganizationUser: Website.objects.filter(account__account_users__user=request.user.) If |
Beta Was this translation helpful? Give feedback.
-
I think @bennylope answer would work too and is achieved in a single line. My answer is from the opposite direction. The reason the relation is called core_accountuser is only because i placed the accountuser under an app called
|
Beta Was this translation helpful? Give feedback.
I think @bennylope answer would work too and is achieved in a single line.
My answer is from the opposite direction.
The reason the relation is called core_accountuser is only because i placed the accountuser under an app called
core
. Your actual relation name may vary.