Skills = PersonSkillSerializer(many=True):Įxperience_level = CharField(max_length=20) Name = CharField(allow_blank=True, max_length=30, required=False) Id = IntegerField(label='ID', read_only=True) When i change the return value in the create function to, user=): I found this reddit solution but was unable to get it to work correctly with my code. SkillSerializer should have the attribute skill_type. Original exception text was: 'ManyRelatedManager' object has no attribute 'skill_type'.Īnd I don't really understand what I am doing wrong. The serializer field might be named incorrectly and not match any attribute or key on the ManyRelatedManager instance. Whenever I hit the endpoint with a POST, it creates the Person and PersonSkill objects correctly, but I get this error:ĪttributeError: Got AttributeError when attempting to get a value for field skill_type on serializer SkillSerializer. Skill_name = skill.get('skill').get('name')Įxperience_level = skill.get('experience').get('experience_level')Į_l = (experience_level=experience_level) Skill_data = validated_data.pop('skills') Skills = PersonSkillSerializer(many=True) My Serializers: class SkillSerializer(serializers.ModelSerializer):Ĭlass ExperienceSerializer(serializers.ModelSerializer):Ĭlass PersonSkillSerializer(serializers.ModelSerializer):Ĭlass PersonSerializer(serializers.ModelSerializer): # create class to serializer model Person = models.ForeignKey(person, related_name='person', on_delete=models.CASCADE)Įxperience = models.ForeignKey(ExperienceLevel, related_name='experience', on_delete=models.CASCADE) Skill = models.ForeignKey(Skill, related_name='skills', on_delete=models.CASCADE) Skill_type = models.CharField(max_length=20)Įxperience_level = models.CharField(max_length=20) Skills = models.ManyToManyField('Skill', through='PersonSkill', related_name='skill') I have started using a M2M relationship and it is working quite well, I have "create" working for creating a new model entry and filling out the associated "through" model, but I am running into an issue with the output serialization (I believe). I am working on a project and have posted previous questions here and here. I think it may have to do with my related_names, but I am not 100% sure.
Now that it is referring to the data as person, the serializer is working. It seems that when its titled person the serializer works perfectly. Skills = EmployeeSkillSerializer(source='person', many=True), as well as popping person instead of skill. Inside the PersonSerializer, I changed the line to this: I ended up getting it working, but I don't understand how or why it works.