16 lines
522 B
Python
16 lines
522 B
Python
from django.db.models import Q
|
|
from qrtr_account.models import Account
|
|
|
|
|
|
class OwnedAccountsMixin():
|
|
"""Mixin to help getting a list of accounts
|
|
the given user is authorized to see
|
|
"""
|
|
|
|
def accessible_accounts(self):
|
|
usr = self.request.user
|
|
accs = Account.objects.filter(Q(owner=usr) |
|
|
Q(id__in=usr.admin_accounts.all().values_list('id')) |
|
|
Q(id__in=usr.view_accounts.all().values_list('id')))
|
|
return accs
|