开发者

Django inline formset - get saved object

if formset.is_valid():
      formset.save()

Hello, how can i get saved in开发者_如何学Goline formset object? In fact my formset hase no unique field.


formset.save() will return a list of instances saved.

You could also go through each form within the formset and save them individually with:

for form in formset:
    myobject = form.save()

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#saving-objects-in-the-formset


If I'm understanding correctly, you want access to the saved model instance, that can be done simply with:

if formset.is_valid():
    my_object = formset.save() # my_object now refers to the model instance.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜