def filter_products(queryset, user):
 if user.is_staff:
  return queryset
 return queryset.filter(stockrecords__partner__users__pk=user.pk).distinct()

def filter_products ( queryset , user ) : if user . is_staff : return queryset return queryset . filter ( stockrecords__partner__users__pk = user . pk ) . distinct ( )
restrict the queryset to products the given user has access to .