Answer the question
In order to leave comments, you need to log in
How to send a QuerySet from the front?
From the front, I pass category IDs for the user. {"specialty":[10,11]}
DRF apparently needs a QuerySet, swears like this
non_field_errors [ "Invalid data. Expected a dictionary, but got int." ]
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = '__all__'
class CreateAccountSerializer(serializers.ModelSerializer):
specialty = CategorySerializer(many=True)
class Meta:
model = Account
fields = '__all__'
class Account (models.Model):
specialty = models.ManyToManyField(Catalog, default='')
"specialty":[{"name":"Rally","id":10}]I am getting this error
Field 'id' expected a number but got {'name': 'Rally', 'id': 10}.
account.specialty.set(self.request.data.get('specialty'))
for i in self.request.data.get('specialty'):
account.specialty.set(i.get('id')) // 'int' object is not iterable
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question