Как создать тип graphql для модели django, которая имеет поля типа «многие-ко-многим
У меня есть модель django с именем profiles. В ней есть несколько базовых полей и поле followers (многие-ко-многим). Это поле содержит список последователей и следующих за ними людей
class Profile(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE)
birth_date = models.DateField(
null=True,
blank=True)
profile_picture = models.ImageField(
upload_to='user_profile_pictures/',
blank=True,
null=True)
cover_picture = models.ImageField(
upload_to='user_cover_pictures/',
blank=True,
null=True)
profile_description = models.TextField(
blank=True,
null=True)
profile_rating = models.IntegerField(
default=0)
followers = models.ManyToManyField(
'self',
symmetrical=False,
related_name='following',
blank=True)
Я использовал chatGpt для создания типа для этой модели
class ProfileType(DjangoObjectType):
class Meta:
model = Profile
fields = "__all__"
followers = graphene.List(lambda: ProfileType)
following = graphene.List(lambda: ProfileType)
followers_count = graphene.Int()
following_count = graphene.Int()
def resolve_followers(self, info):
return self.followers.all()
def resolve_following(self, info):
return self.following.all()
def resolve_followers_count(self, info):
return self.followers.count()
def resolve_following_count(self, info):
return self.following.count()
Этот вопрос связан с тем, что у графенового списка нет методов all() и count(). Как мне следует обращаться с этим полем?