eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 108 forks source link

How to filter QuerySet in DjangoSerializerType ? #166

Open kentuck13 opened 3 years ago

kentuck13 commented 3 years ago

I have articles. Each user must be read only their own articles. -> Articles.objects.filter(user=request.user)


class ArticleModelType(DjangoSerializerType):
    class Meta:
        filter_fields = {
            'name': ['exact'],
            'category': ['exact'],
            'category__name': ['exact']
        }
        serializer_class = ArticleSerializer

class Query(graphene.ObjectType):
    article, articles = ArticleModelType.QueryFields()

I still haven't found a place where I should put this QuerySet = Articles.objects.filter(user=request.user)