from django.forms.models import model_to_dict
top_flow_obj = FlowObject.objects.filter().last()
to_flow_dict = model_to_dict(top_flow_obj)
print(to_flow_dict)
item_ser = AddBudgetDetailSerializer(data=to_flow_dict,context={'request': request})
print(to_flow_dict)
if not item_ser.is_valid():
print('写入支出明细时发生错误,错误原因如下')
print(str(item_ser.errors))
else:
item_ser.save()
Django 中将模型对象转换成dict对象后利用serializer来保存
最新推荐文章于 2024-05-29 13:43:16 发布