когда я хочу сохранить экземпляр моей модели, многие из многих полей не были сохранены. Я пробовал с кодами ниже:
модели:
class Attachment(models.Model):
test = models.TextField()
class PlanComment(models.Model):
attachment = models.ManyToManyField('Attachment', blank=True)
comment = models.TextField()
сериализаторы:
class AttachmentSerializer(serializers.ModelSerializer):
class Meta:
model = Attachment
fields = ['test']
class PlanCommentSerializer(serializers.ModelSerializer):
attachment = AttachmentSerializer(many=True, read_only=True)
class Meta:
model = PlanComment
fields = [
'id',
'attachment',
]
просмотров:
class PlanCommentViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows plan comment to be viewed or edited.
"""
queryset = PlanComment.objects.all().order_by('-id')
serializer_class = PlanCommentSerializer
мои параметры:
{
"attachment": [1],
"comment": "Test"
}