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 6868187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:11+00:00 2026-05-27T03:24:11+00:00

Say I have django model that looks something like this: class Order(models.Model): number =

  • 0

Say I have django model that looks something like this:

class Order(models.Model):
 number = models...
 date = models...

class OrderLine(models.Model):
 # One or more lines per order
 order = models.ForeginKey(Order)
 common_line = models.OneToOneField(CommonLine)

class CommonLine(models.Model):
 # common elements of what might be on a line item...
 taxes = model...
 amount = model...

I want to create a form that uses an inlineformset to edit one or more Lines (both OrderLine and CommonLine) per order.

I can create a formset that works with Order and OrderLine – but how do I get the inline formset to give me all the detailed items from the CommonLine class when displaying the formset. It seems the documentation on inline formsets requires that the inline form – the multiple lines on an order can only map to a single class…

Am I not seeing something in the documentation? I’m sure I can probably override something, I’m just not sure where.

Thanks for any help…

  • 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-27T03:24:12+00:00Added an answer on May 27, 2026 at 3:24 am

    Some minor changes were needed to make Nathan’s code at http://yergler.net/blog/2009/09/27/nested-formsets-with-django/ work in Django 1.3. The line below causes a ManagementForm Error.

    TenantFormset = inlineformset_factory(models.Building, models.Tenant, extra=1)

    Usings the modelformset_factory and manually defining the queryset seems to work, but I have not implemented the ability to add extras.

    TenantFormset = modelformset_factory(models.Tenant, extra=0)
    
    form.nested = [
            TenantFormset(
                            queryset = Tenant.objects.filter(building = pk_value),
                            prefix = 'value_%s' % pk_value
                            )
                        ]
    

    I also had to manually pass data to the sub-sub-forms in the is_valid method:

    def is_valid(self):
    result = super(BaseProtocolEventFormSet, self).is_valid()
    
    for form in self.forms:
        if hasattr(form, 'nested'):
            for n in form.nested:
                n.data = form.data
                if form.is_bound:
                    n.is_bound = True
                for nform in n:
                    nform.data = form.data
                    if form.is_bound:
                        nform.is_bound = True
                # make sure each nested formset is valid as well
                result = result and n.is_valid()
    return result
    

    EDIT:

    New instances can be created using jQuery. See this question:

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

Sidebar

Related Questions

Say I have some django models, something like this: class Address(models.Model): pass class Person(models.Model):
Say I have a model that looks like: class StockRequest(models.Model): amount_requested = models.PositiveIntegerField(null=True) amount_approved
Say I have a model that looks like: class Action(models.Model): user = models.ForeignKey('auth.User') action
Say I have two models in my Django project. class Project(models.Model): name = models.CharField(max_length=256)
Let's say that I have a model: class Ticket(models.Model): client = models.ForeignKey(Client) color =
Say I have a class named Frog, it looks like: public class Frog {
I have a model which is accessible through the Django admin area, something like
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
I have these Django models: class Group(models.Model): name = models.CharField(max_length=100) parent_group = models.ManyToManyField("self", blank=True)
Say I have the following model: class Person(models.Model): street_address = models.CharField(max_length=50, blank=True) suburb =

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.