1
我有一個模型場的空= True和空白=真串行無誤差JS
class Question(models.Model):
question = models.TextField(blank=False, null=False)
question_image = models.ImageField(blank=True, null=True, upload_to='question')
option = ArrayField(models.CharField(max_length=50, blank=False, null=False),size=4)
answer = models.IntegerField(choices=((1,'1'),(2,'2'),(3,'3'),(4,'4')))
description = models.TextField(blank=True,null=True)
coressponding串是
class QuestionSerializer(serializers.ModelSerializer):
class Meta:
model = Question
fields = ('id', 'question', 'question_image', 'option', 'answer', 'description')
read_only_fields = ('id',)
的序列化對象我得到的是
{'description':None,'id':1,'answer':3,'question_image':None,'option':['27','28','29','31'],'question' :'印度有多少州?'}
我想在JavaScript中使用這個JSON,它給我錯誤None
沒有定義。在串行器中將None更改爲null的最簡單和乾淨的解決方案是什麼?