#NEWLINE# def filter_products( queryset , user ) : #NEWLINE# #INDENT# "\n    Restrict the queryset to products the given user has access to.\n    A staff user is allowed to access all Products.\n    A non-staff user is only allowed access to a product if they are in at\n    least one stock record's partner user list.\n    " #NEWLINE# if user . is_staff : #NEWLINE# #INDENT# return user #NEWLINE# #UNINDENT# return queryset . filter ( stockrecords__partner__users__pk = user . pk ) . distinct ( )