1👍
✅
You can filter out such items by looking for Category
s that have at least one item that is not keywords_1
/keywords_2
, or have no items, so:
from django.db.models import Exists, OuterRef, Q
Category.objects.filter(
Exists(
CategoryGroup.objects.filter(
~Q(label__in=['keywords1', 'keywords2']),
category_group=OuterRef('pk'),
)
)
)
Source:stackexchange.com