diff --git a/qrtr_account/mixins.py b/qrtr_account/mixins.py new file mode 100644 index 0000000..a106358 --- /dev/null +++ b/qrtr_account/mixins.py @@ -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