I want to create a simple serializer that anyone who wants to can add a Question with several answers (how much he needs)
one question, several answers
- I want to be able to add using an assembly in html form and not edit json.
my models:
class Question(models.Model): question_text = models.CharField(max_length=30) class Answer(models.Model): question = models.ForeignKey(Question) answer_text = models.CharField(max_length=40)
my url.py
class AnswerSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Answer fields = ('answer_text',) class QuestionSerializer(serializers.HyperlinkedModelSerializer): answers = AnswerSerializer(many=True) class Meta: model = Question fields = ('question_text', 'answers',) class QuestionViewSet(viewsets.ModelViewSet): queryset = Question.objects.all() serializer_class = QuestionSerializer
now when i start the web i get the message:
"Lists are not currently supported in HTML input."
please, help:)
edit first
even when I delete ("many = True"), I get an error when trying to send a message:
AssertionError at / questions / The .create() method does not by default support .create() nested fields. Write an explicit .create() method for serializer api_project2.urls.QuestionSerializer or set read_only=True on serializer nested fields.
thats creates m second problem: the create () method, which I do not know how to edit
source share