Basic models:

class ModelA(Model):
    name = CharField(...)


class ModelB(Model):
    model_a = ManyToManyField(ModelA, blank=True)
class ModelBFilter(filters.FilterSet):
    unassigned = BooleanFilter(field_name='model_a', lookup_expr='isnull')

    class Meta:
        model = ModelB
        fields = ['unassigned']

How do I filter (with django-filter) to find the ModelB's that do not have a corresponding related model?

0 Answers