0👍
schema.py
class TeacherNode(DjangoObjectType):
favorite = graphene.List(RemarkNode)
def resolve_favorite(self, info, **kwargs):
remarks = Remarks.objects.filter(teacher=self.id)
return remarks
class Meta:
model = Teacher
filter_fields = ['name', 'subject']
interfaces = (relay.Node, )
class StudentNode(DjangoObjectType):
class Meta:
model = Student
filter_fields = {
'name': ['exact', 'icontains', 'istartswith'],
'age': ['exact'],
}
interfaces = (relay.Node, )
class TeacherQuery(graphene.ObjectType):
teacher = relay.Node.Field(TeacherNode)
all_teachers = DjangoFilterConnectionField(TeacherNode)
student = relay.Node.Field(StudentNode)
all_students = DjangoFilterConnectionField(StudentNode)
👤aref
Source:stackexchange.com