Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:57+00:00 2026-05-26T21:11:57+00:00

Sorry for the question title, i didn t know how to explain the question

  • 0

Sorry for the question title, i didn t know how to explain the question briefly.

Basicly i m on a situation like this:

models.py

class Author(Model):
    ...

class Book(Model)
    author = models.ForeignKey(Author)

views.py

for author in Author.objects.filter(name=""):
    author_form = AuthorForm(instance=author) #This is a model form
    book_formset = inlineformset_factory(Author, Book, instance=author)

What i’d like to do now, is to create a formset of authors. Each element should contain an istance of AuthorForm and the related book_formset.

Any idea on how to do it??

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:11:58+00:00Added an answer on May 26, 2026 at 9:11 pm

    This person may have done what you are asking about but I don’t think it’s what you need.

    If I understand you correctly, you are close, but should be using the factory (not the factory generator function) multiple times to create a list where each element has two separate items: the author form and the inline formset with the books. The key point being you will have two separate items rather than one inside the other.

    Each form/inline formset will need a unique prefix to identify it relative to the others in the rendered html/form soup.

    In your view:

    AuthorBooksFormSet = inlineformset_factory(Author, Book)
    author_books_list = list()
    for author in author_queryset: #with whatever sorting you want in the template
        prefix = #some unique string related to the author
        author_form = AuthorForm(instance=author,
                                 prefix='author'+prefix)
        author_books_formset = AuthorBooksFormSet(instance = author,
                                                  prefix = 'books'+prefix)
        author_books_list.append((author_form, author_books_formset))
    

    Send the whole list to your template and:

    {% for author_form, author_books_formset in author_books_list %}
        ...something with author_form
        ...something with author_books_formset
    {% endfor %}
    

    You may even be able to skip the author form if django provides a form for the instance object in the formset. But I’ve never used them so I’m not sure.

    I guess you have moved on since I found this late through a google search, but what did you eventually do?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sorry I didn't know how to title my question any better, you
Sorry for the terrible Question Title, I don't know how to phrase this, feel
Sorry about the rubbish question title. I have a table SET_DEFINITIONS like this: SETKEY
Sorry, I don't really know how to title this question. Here's my code in
I certainly don't know how to title this question, sorry. I'm having some problems
Sorry if the question title is confusing. Let me explain further. I am building
I'm sorry if my question title seems fundamentally uninformed. Let me explain what I
[ Update: Changed question title to be more specific] Sorry if I didn't make
I know that title didn't make sense, Im sorry! Its hard to word what
Sorry for the bad question title. Let's say that I have DateRange class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.