I am trying to understand how I should be structuring my post call when I want to do a many to many relationship.
class School(models.Model):
name = models.CharField(unique=True, max_length=30, blank=True)
teachersAtSchool = models.ManyToManyField('Teacher', blank=True)
class Teacher(models.Model):
account = models.ForeignKey(Account, default=1, on_delete=models.SET_DEFAULT)
schoolsTeachingAt = models.ManyToManyField('School', blank=True)
I send in the following JSON:
{
"name": "school Name",
"teachersAtSchool": 0
}
and get the following result:
{
"id": 13,
"name": "school Name",
"teachersAtSchool": []
}
Edit: Showing serialize
class SchoolModelSerializer (serializers.ModelSerializer):
class Meta():
model = models.School
fields = '__all__'
depth = 1
class TeacherModelSerializer (serializers.ModelSerializer):
class Meta():
model = models.Teacher
fields = '__all__'
depth = 1
I have checked there are indeed teachers in the database that I can get with my GET call. I even tried with different id's but I get the same result. Its possible this is something super simple I just don't understand. Please help me.
Regards