move avail accounts mixin to account mixins file. Add avail accounts mixin to Connection viewsets
This commit is contained in:
parent
1411fbdf53
commit
20aa85bf08
15
qrtr_account/mixins.py
Normal file
15
qrtr_account/mixins.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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
|
||||||
Loading…
Reference in New Issue
Block a user