Ошибка mutation grapiql django набор "многие ко многим" запрещен. Вместо этого используйте films.set()

У меня есть следующие модели:

######################################################

class People(TimeStampedModel, SimpleNameModel):
""" Personajes del universo de Star Wars """
MALE = 'male'
FEMALE = 'female'
HERMAPHRODITE = 'hermaphrodite'
NA = 'n/a'

GENDER = (
    (MALE, 'Male'),
    (FEMALE, 'Female'),
    (HERMAPHRODITE, 'Hermaphrodite'),
    (NA, 'N/A'),
)

HAIR_COLOR_CHOICES = (
('BLACK', 'black'),
('BROWN', 'brown'),        
('BLONDE', 'blonde'),
('RED', 'red'),
('WHITE', 'white'),
('BALD', 'bald'),
)

EYE_COLOR_CHOICES = (
('BLACK', 'black'),
('BROWN', 'brown'),        
('YELLOW', 'yellow'),
('RED', 'red'),
('GREEN', 'green'),
('PURPLE', 'purple'),
('UNKNOWN', 'unknown'),
)

height = models.CharField(max_length=16, blank=True)
mass = models.CharField(max_length=16, blank=True)
# hair_color = models.CharField(max_length=32, blank=True)
hair_color = models.CharField(max_length=32, choices=HAIR_COLOR_CHOICES, blank=True)
skin_color = models.CharField(max_length=32, blank=True)
# eye_color = models.CharField(max_length=32, blank=True)
eye_color = models.CharField(max_length=32, choices=EYE_COLOR_CHOICES, blank=True)
birth_year = models.CharField(max_length=16, blank=True)
gender = models.CharField(max_length=64, choices=GENDER)
home_world = models.ForeignKey(Planet, on_delete=models.CASCADE, related_name='inhabitants')


class Meta:
    db_table = 'people'
    verbose_name_plural = 'people'

######################################################

class Film(TimeStampedModel):
title = models.CharField(max_length=100)
episode_id = models.PositiveSmallIntegerField()  # TODO: Agregar choices
opening_crawl = models.TextField(max_length=1000)
release_date = models.DateField()
director = models.ForeignKey(Director, on_delete=models.CASCADE, related_name='films')
producer = models.ManyToManyField(Producer, related_name='films')
characters = models.ManyToManyField(People, related_name='films', blank=True)
planets = models.ManyToManyField(Planet, related_name='films', blank=True)

class Meta:
    db_table = 'film'

def __str__(self):
    return self.title

######################

class People_film(People):
    films = models.ManyToManyField(Film, related_name='film', blank=True)

Я делаю мутацию в graphiql, чтобы при добавлении людей я мог также добавлять фильмы, в которых они снимались

mutation {
     createPeople(name: "jhonatan ibarra", height: "ejemplo", birthYear: "00/00/000", 
       eyeColor: "red", gender: "male", hairColor: "red", mass: "ejemplo", skinColor: 
     "red", homeWorldId: 2, peopleFilmId:"Revenge of the Sith") {
        people {
       name
      }
    }
}

Но появляется следующая ошибка :

{
   "errors": [
    {
             "message": "Direct assignment to the reverse side of a many-to-many set is 
          prohibited. Use films.set() instead.",
     "locations": [
        {
       "line": 2,
           "column": 3
        }
        ],
          "path": [
          "createPeople"
         ]
    }
    ],
    "data": {
     "createPeople": null
 }
   }

Код для создания(мутации следующий):

class CreatePeople(graphene.Mutation):
people = graphene.Field(PeopleFilmType)

class Arguments:
    name= graphene.String()
    height = graphene.String()
    mass = graphene.String()
    hair_color = graphene.String()
    skin_color = graphene.String()
    eye_color = graphene.String()
    birth_year = graphene.String()
    gender = graphene.String()
    home_world_id = graphene.Int()
    people_film_id = graphene.String()


def mutate(self, info, name, height,mass,hair_color,skin_color,eye_color,birth_year,gender,home_world_id, people_film_id):
    p = People(name=name, height=height,mass=mass,hair_color=hair_color,skin_color=skin_color,eye_color=eye_color,birth_year=birth_year,gender=gender)
    hw = Planet.objects.get(id=home_world_id)
    pf = Film.objects.get(title=people_film_id)
    p.home_world = hw
    p.films = pf
    p.save()
    return CreatePeople(people=p)

Как я могу исправить эту ошибку, в мутации. спасибо большое

Вернуться на верх