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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:21:50+00:00 2026-05-24T00:21:50+00:00

I have the following models: class Bill(models.Model): date = models.DateTimeField(_(Date of bill),null=True,blank=True) class Item(models.Model):

  • 0

I have the following models:

class Bill(models.Model):
    date = models.DateTimeField(_("Date of bill"),null=True,blank=True)

class Item(models.Model):
    name = models.CharField(_("Name"),max_length=100)
    price = models.FloatField(_("Price"))
    quantity = models.IntegerField(_("Quantity"))
    bill = models.ForeignKey("Bill",verbose_name=_("Bill"),
                             related_name="billitem")

I know that this is possible:

from django.forms.models import inlineformset_factory
inlineformset_factory(Bill, Item)

and then process this via standard view.

Now I was wondering, if there is a way to achieve the same (meaning: using a inline for adding/editing items belonging to a bill) using class based views (not for the admin-interface).

  • 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-24T00:21:52+00:00Added an answer on May 24, 2026 at 12:21 am

    Key points is:

    1. generated FormSets within forms.py using inlineformset_factory:

      BookImageFormSet = inlineformset_factory(BookForm, BookImage, extra=2)
      BookPageFormSet = inlineformset_factory(BookForm, BookPage, extra=5)
      
    2. returned the FormSets within a CreateView class in views.py:

      def get_context_data(self, **kwargs):
          context = super(BookCreateView, self).get_context_data(**kwargs)
          if self.request.POST:
              context['bookimage_form'] = BookImageFormSet(self.request.POST)
              context['bookpage_form'] = BookPageFormSet(self.request.POST)
          else:
              context['bookimage_form'] = BookImageFormSet()
              context['bookpage_form'] = BookPageFormSet()
          return context
      
    3. Used form_valid to save the form and formset:

       def form_valid(self, form):
           context = self.get_context_data()
           bookimage_form = context['bookimage_formset']
           bookpage_form = context['bookpage_formset']
           if bookimage_form.is_valid() and bookpage_form.is_valid():
               self.object = form.save()
               bookimage_form.instance = self.object
               bookimage_form.save()
               bookpage_form.instance = self.object
               bookpage_form.save()
               return HttpResponseRedirect('thanks/')
           else:
               return self.render_to_response(self.get_context_data(form=form))
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following models class Artist(models.Model): name = models.CharField(max_length=200, unique=True) photo = models.CharField(max_length=250) views
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
I have the following models: class Category(models.Model): name = models.CharField(max_length=40) class Item(models.Model): name =
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model): title =
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
Let's say I have the following model: class Contest: title = models.CharField( max_length =
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)
i have the following models: class Tag(models.Model): tag_name = models.CharField(max_length=250) tagcat = models.ForeignKey('TagCat') class

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.