问候!我是Django石墨烯的新手。我通过Course
拥有User
和Participation
之间的以下m对n关系:
class Course(models.Model):
participants = models.ManyToManyField(get_user_model(), through='Participation')
class Participation(models.Model):
COURSE_ROLE = [(0, "student"),(1, "mentor"),(2, "tutor"),(3, "owner")]
course = models.ForeignKey('exquizit.Course', on_delete=models.CASCADE)
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
course_role = models.SmallIntegerField(choices=COURSE_ROLE)
class User(AbstractBaseUser):
first_name = models.CharField(max_length=100, blank=False)
last_name = models.CharField(max_length=100, blank=False)
我想编写一个查询来加载给定课程的参与者(按ID)。我想以这样一种方式来编写它:实质上是返回用户,但通过course_role
的{{1}}属性进行了扩展。我知道
Participation
但这会导致
class ParticipantType(DjangoObjectType):
course_role = graphene.Int()
user = graphene.Field(User)
当我真正想要的时候
{
user: {firstName: "Alice", lastName: "Anderson"},
course_role: 1
}
如果可能,请提供{
participant: {firstName: "Alice", lastName: "Anderson", course_role: 1}
}
和查询解析器!
感谢您提供任何答案或提示!