[Fixed]-How to access auto increment id of any model using form in django?

1👍

save() returns the object, so you just need to do

publisher_obj = form3.save()
author_obj = form2.save()
book_obj = form1.save(commit=False)
book_obj.publisher = publisher_obj
book_obj.save()
book_obj.authors.add(author_obj)

and remove the ‘id’ from the form. You don’t need it.

Leave a comment