Hey, I would like to implement a Django form corresponding to a model. So the model is a Book. A Book has Chapters (another model linked with a ForgeinKey). A Chapter has multiple Paragraphs (model linked via ForgeinKey, too). How would you put this model in a html form such as a user could add a Book? This is a fictional Model but is summarises well the one I want to implement. Thanks a lot for reading, I am opened to any suggestion. Jude
For clarity, are you asking about adding only a
Book, or are you looking for a way to add a
Book with one (or more)
Chapter - each of which with one (or more)
Oh my bad, I would like to add all three in one form.
You could do this using nested formsets.
You could have a form for a book. Within that book you could create a formset for the chapters. Then, within each chapter you could have a formset for the paragraphs.
Take a look at the discussions at Multiples of one formset and how to save two model formsets together(relates to each other) in one view for some ideas related to this.
I’ll check this. Thank you so much regardless. I appreciate it a lot!