Having this code sequence:
queryset = self.filter(
brand_id__in=(
UserObjectPermission.objects.filter(
content_type=brand_ctype,
user=user,
).values_list('object_pk')
)
)
If there is no UserObjectPermission object that matches the filter content_type=brand_ctype, user=user then the end result will be empty queryset, because brand_id __in will search in [empty queryset].
But I need the reverse. If there is no UserObjectPermision object for this filter (content_type=brand_ctype, user=user) then return all objects, that is, ignore this filter (
brand_id__in=(UserObjectPermission.objects.filter(
content_type=brand_ctype,
user=user,
).values_list('object_pk')
)
I need the brand_id__in filter to run only if there is at least one object in the queryset.