更新时间:2023-12-01 21:57:52
当您保存模型表单时,它会返回已保存的模型实例.所以你所要做的就是将它分配给一个变量:
When you save a modelform, it returns the saved instance of the model. So all you have to do is assign it to a variable:
f = MyModelForm(request.POST)
if f.is_valid():
m = f.save()
除非您要处理更复杂的数据,否则您无需使用 commit=False
或任何其他东西.
You do not need to mess around with commit=False
or any of that stuff unless you are handling more complex data.