Skip to content

How to create a filter "not equal" and "not in" #1162

Answered by tcleonard
acrispim asked this question in Q&A
Discussion options

You must be logged in to vote

Note that in result/types.py you should not need to do:

object = DjangoFilterConnectionField(ObjectType)

To achieve what you want you need to declare a filter in a filterset_class like so:

from django_filters import Filter, FilterSet
from graphene_django.filter import ListFilter

class ResultFilterSet(FilterSet):
    class Meta:
        model = Result
        fields = {
            "object__object_name": ["exact", "icontains"],
        }

    object__object_name_notequal = Filter(field_name="object__object_name", lookup_expr="exact", exclude=True)
    object__object_name_notin = ListFilter(field_name="object__object_name", lookup_expr="in", exclude=True)

class ResultType(DjangoObjectType)…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1145 on April 14, 2021 20:01.