0
因爲我發佈文件,我不得不使用$ http和FormData對象。當我發佈一個帶有一個數組的實例時,驗證表明我沒有發佈一個整數。使用FormData發佈/修補到Django ArrayField
我的模型看起來是這樣的:
class User(models.Model):
work_week = ArrayField(models.IntegerField(), default=[0,1,2,3,4], size=7)
我的串行看起來是這樣的:
class UserSerializer(serializer.ModelSerializer):
work_week = serializers.ListField(
child=serializers.IntegerField(min_value=0, max_value=6)
)
的JavaScript後看起來像這樣
let data = {
work_week = [1,2,3];
}
let fd = new FormData();
for (let [key, val] of Object.entries(data)) {
if (key === 'work_week') {
val = JSON.stringify(val);
}
fd.append(key, val)
}
$http({
url: full_url,
method: this.method,
data: fd,
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
該錯誤消息我得到是:
{work_week: ["A valid integer is required."]}