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.
精彩评论