Hi. I stumbled upon an error today and I am not sure whether it is a bug or if I am missing something.
I have two models with a many-to-many relation between them:
class Movie(models.Model):
name = models.TextField()
class Actor(models.Model):
name = models.TextField()
movies = models.ManyToManyField(Movie, related_name="actors")
I'd like to create and update these entities from both sides so I have the following serializers:
class ActorNestedSerializer(serializers.ModelSerializer):
class Meta:
model = models.Actor
fields = ["pk", "name"]
class MovieNestedSerializer(serializers.ModelSerializer):
class Meta:
model = models.Movie
fields = ["pk", "name"]
class ActorSerializer(WritableNestedModelSerializer):
movies = MovieNestedSerializer(many=True)
class Meta:
model = models.Actor
fields = ["pk", "name", "movies"]
class MovieSerializer(WritableNestedModelSerializer):
actors = ActorNestedSerializer(many=True)
class Meta:
model = models.Movie
fields = ["pk", "name", "actors"]
When I create or update an Actor with Movies, everything works fine:
Hi. I stumbled upon an error today and I am not sure whether it is a bug or if I am missing something.
I have two models with a many-to-many relation between them:
I'd like to create and update these entities from both sides so I have the following serializers:
When I create or update an
Actor
withMovies
, everything works fine:When trying to do the same but in reverse direction (create or update a
Movie
withActors
), it raises an Exception when trying to update theMovie
:It raises the following error:
django.core.exceptions.FieldError: Cannot resolve keyword 'actors' into field. Choices are: id, movies, name
Stacktrace:
Any help is much appreciated, thank you!