Skip to content

Instantly share code, notes, and snippets.

@Fercho191
Last active December 5, 2018 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fercho191/84d18f74664e8eb89b588a890d523d46 to your computer and use it in GitHub Desktop.
Save Fercho191/84d18f74664e8eb89b588a890d523d46 to your computer and use it in GitHub Desktop.
Graphene schema with CustomFiltersets
from graphene_django import DjangoObjectType
from graphene import relay, AbstractType
from graphene_django.filter import DjangoFilterConnectionField
from app.models import Leather
from django_filters import FilterSet, OrderingFilter
class LeatherFilterSet(FilterSet):
order_by = OrderingFilter(
fields=(
('created', 'created'),
)
)
class Meta:
model = Leather
fields = {
'name': ['exact', 'icontains', 'istartswith']
}
class LeatherNode(DjangoObjectType):
class Meta:
model = Leather
interfaces = (relay.Node,)
class Query(AbstractType):
leather = relay.Node.Field(LeatherNode)
leathers = DjangoFilterConnectionField(
LeatherNode,
filterset_class=LeatherFilterSet
)
@cricri92
Copy link

Hi! Works like a charm! But you have a typo in leathers query, when you're using PhotoNode, instead of LeatherNode.

@Fercho191
Copy link
Author

Hi! Works like a charm! But you have a typo in leathers query, when you're using PhotoNode, instead of LeatherNode.

You right.. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment