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

  • Home
  • SEARCH
  • 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 8434455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:39:38+00:00 2026-06-10T06:39:38+00:00

I have some models, connected with GenericForeignKey : Class Main(models.Model) filed_1 = models.CharField(max_length=20) object_id

  • 0

I have some models, connected with GenericForeignKey:

Class Main(models.Model)
    filed_1      = models.CharField(max_length=20)
    object_id    = models.PositiveIntegerField()
    content_type = models.ForeignKey(ContentType)
    object       = generic.GenericForeignKey('content_type', 'object_id')

Class Additional_1(models.Model):
    f_1 = models.CharField(max_length=20)
    f_2 = models.CharField(max_length=20)

Class Additional_2(models.Model):
    d_1 = models.CharField(max_length=20)
    d_2 = models.CharField(max_length=20)

And forms for this models:

Class MainForm(forms.ModelForm):
      class Meta:
           model  = Main
           fields = ('filed_1', 'object_id', 'content_type')

           widgets = {
               'object_id': forms.HiddenInput,
               'content_type': forms.HiddenInput
           }

Class Additional_1Form(forms.ModelForm):
    class Meta:
        model  = Additional_1
        fields = ('f1', 'f2')

Class Additional_2Form(forms.ModelForm):
    class Meta:
        model  = Additional_2
        fields = ('d1', 'd2')

How to make forms, composed of fields of MainForm + Additional_iForm in one html form with one submit button (MainForm + Additional_1Form and Main + Additional_2Form) and provide correct creating and editing. There is way to do it using standard Django components, like inline formset for ForeignKey?

P.S. I think the answer to this question should be contained in this section of the documentation, but there is too little information to answer. https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations-in-forms-and-admin

EDITION #1

# This is always false, because of 'object_id' in main_form
if main_form.is_valid() and additional_1_form.is_valid():
    additional = additional_1_form.save()
    main_form.object_id = additional .id # I need something like this to set object_id 
    main_form.save()
  • 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-06-10T06:39:40+00:00Added an answer on June 10, 2026 at 6:39 am

    Create one form tag:

    <form action="..." method="POST">
    {{ main_form }}    
    {{ additional_form_1 }}    
    {{ additional_form_2 }}
    <input type="submit" value="Submit!">
    </form>
    

    where {{ mainform }}, {{ additional_form_1 }} and {{ additional_form_2 }} are the HTML that Django generates for each of each of the forms. You can add editing feedback or additional functionality using JavaScript (such as filling in values when the user has selected a particular value for a particular field).

    In the back-end, you can then check whether each of the forms is valid:

    if (main_form.is_valid() and
       additional_form_1.is_valid() and
       additional_form_2.is_valid()):
       pass
    

    If not, you can display errors in the form page again.

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

Sidebar

Related Questions

I have these models: class Gallery(models.Model): HeadImage = models.ImageField(upload_to=gallery,blank=True,null=True) class News(Gallery): Name=models.CharField(max_length=100) #some other
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
What I have: QTreeView class with table data And connected QAbstractTableModel model Question :
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
I have some models witch are using Doctrine nestedset feature. I want to add
I have some models that are laid out like so (with a lot more
Let's say I have some models: User , Post , and Vote . A
I have created a play application and have some models. One of them contains
I have some nested models in my Rails application. i have an article hat
I have some Mongoose Models with geospacial indexes: var User = new Schema({ name

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.