Skip to content

Commit

Permalink
feat: add types classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SquakR committed Jan 31, 2022
1 parent 4ce26c8 commit b762b40
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/filter_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class UserFilter(django_filters.FilterSet):

class Meta:
model = User
fields = [
fields = (
'first_name',
'last_name',
'sir_name',
'email',
'is_active',
'birthday',
]
)


class TaskFilter(django_filters.FilterSet):
Expand All @@ -35,7 +35,7 @@ class TaskFilter(django_filters.FilterSet):

class Meta:
model = Task
fields = [
fields = (
'name',
'user__last_name',
]
)
57 changes: 57 additions & 0 deletions tests/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Types classes."""

import graphene
from graphene_django import DjangoObjectType

from .filter_set import TaskFilter, UserFilter
from .models import Task, User


class UserFilterFieldsType(DjangoObjectType):
"""UserType with the `filter_fields` field in the Meta class."""

class Meta:
model = User
fields = '__all__'
filter_fields = {
'first_name': ('exact',),
'last_name': ('exact',),
'sir_name': ('exact',),
'email': ('exact',),
'is_active': ('exact',),
'birthday': ('exact',),
}


class UserFilterSetClassType(DjangoObjectType):
"""UserType with the `filterset_class` field in the Meta class."""

class Meta:
model = User
fields = '__all__'
filterset_class = UserFilter


class TaskFilterFieldsType(DjangoObjectType):
"""TaskType with the `filter_fields` field in the Meta class."""

user = graphene.Field(UserFilterFieldsType, description='User field')

class Meta:
model = Task
fields = ('name', 'user')
filter_fields = {
'name': ('exact',),
'user__email': ('iexact', 'contains', 'icontains'),
}


class TaskFilterSetClassType(DjangoObjectType):
"""TaskType with the `filterset_class` field in the Meta class."""

user = graphene.Field(UserFilterSetClassType, description='User field')

class Meta:
model = Task
fields = ('name', 'user')
filterset_class = TaskFilter

0 comments on commit b762b40

Please sign in to comment.