def queryset_orders_for_user(user):
 queryset = Order._default_manager.select_related('billing_address', 'billing_address__country', 'shipping_address', 'shipping_address__country', 'user').prefetch_related('lines')
 if user.is_staff:
  return queryset
 else:
  partners = Partner._default_manager.filter(users=user)
  return queryset.filter(lines__partner__in=partners).distinct()

def queryset_orders_for_user ( user ) : queryset = Order . _default_manager . select_related ( 'billing_address' , 'billing_address__country' , 'shipping_address' , 'shipping_address__country' , 'user' ) . prefetch_related ( 'lines' ) if user . is_staff : return queryset else : partners = Partner . _default_manager . filter ( users = user ) return queryset . filter ( lines__partner__in = partners ) . distinct ( )
returns a queryset of all orders that a user is allowed to access .