- 问题
- Postman传递json,drf反序列化时接受不到值,一直提示None
- json数据
点击查看代码
{
"number": "1",
"warehouse": "1",
"members": "1",
"handler": "1",
"handle_time": "2023-01-28",
"remark": "123",
"total_quantity": "10",
"total_amount": "100",
"discount_amount": "0",
"creator": 1,
"pos_goods_items": [
{
"goods": 2,
"sales_quantity": 30,
"sales_price": 2,
"total_amount": 60,
"return_quantity": 0
}
],
"pay_record_items": []
}
- 序列化字段
点击查看代码
read_only_fields = ['id', 'handle_time', 'create_time', 'members_name', 'handler_name', 'creator_name']
fields = ['members', 'warehouse', 'remark', 'total_quantity', 'discount', 'total_amount', 'creator', 'handler',
'number', 'discount_amount', 'is_void', 'enable_auto_stock_out',
'pos_goods_items', 'pay_record_items', *read_only_fields]
- 报错信息
sqlite NOT NULL constraint failed
- 解决办法
- 将model.py中关联的外键,做引入填写
warehouse = ForeignKey(Warehouse, on_delete=PROTECT, related_name='pos_order', verbose_name='仓库')