add a util to get objects for a specific customer

This commit is contained in:
Andreas Zweili 2021-12-24 12:32:28 +01:00
parent 05b87c14cf
commit 819628d008
1 changed files with 8 additions and 2 deletions

View File

@ -86,6 +86,12 @@ def get_objects_with_view_permission(model, user=None):
if model.__name__ == 'Customer':
return customers
objects = model.objects.filter(customer__in=customers)
if not objects:
raise Http404()
return objects
def get_objects_for_customer(model, user=None, customer_pk=None):
customer = get_object_or_404(Customer, id=customer_pk)
if user.has_perm('customers.view_customer', customer):
objects = model.objects.filter(customer=customer)
return objects
raise Http404