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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:12:03+00:00 2026-06-15T07:12:03+00:00

I’m creating the "Order" form for the Parts. My AddOrderForm has Order Model fields

  • 0

I’m creating the "Order" form for the Parts.

My AddOrderForm has Order Model fields (like quantity) but at the same time some Part-related info from Part Model (like name_in_english) and PartNumber Model (like number) and some other fields…

First I did Separate ModelForm for each one and them combined them like this:

forms.py

class PartNumberForAddOrderForm(forms.ModelForm):

    class Meta:
        model = PartNumber
        fields = ('number',)

class PartForAddOrderForm(forms.ModelForm):

    class Meta:
        model = Part
        fields = ('manufacturer','name_in_english')

class AddOrderForm(forms.ModelForm):

    class Meta:
        model = Order
        fields = ('quantity',)

in template:

<form class="form-inline well" id="add_order">
    <div class="row-fluid">
        <div class="span12">

        {% crispy form_part_number %}
        {% crispy form_part %}
        {% crispy form_order %}
        
        <input type="submit" class="btn btn-primary pull-right" value="{% trans 'Add' %}"/>
        </div>
    </div>  
</form>

With this view became:
form_part_number.is_valid() and form_part.is_valid() and form_order.is_valid():

All this looks SUPER ugly and just wrong…

So I created the other way:

class PartForm(forms.ModelForm):

    class Meta:
        model = Part
        fields = ('manufacturer','name_in_english')

class PartNumberForm(forms.ModelForm):

    class Meta:
        model = PartNumber
        fields = ('number',)

class AddOrderForm(forms.ModelForm):
    manufacturer = PartForm.base_fields['manufacturer']
    name_in_english = PartForm.base_fields['name_in_english']
    number = PartNumber.base_fields['number']

    class Meta:
        model = Order
        fields = ('manufacturer','number','quantity','name_in_english')
    

QUESTIONS: Is this Form.base_fields[''] legal way? I assume the .save() will not work, but .is_valid() should be fine, right? Is there any better way to do it?

I could fine anything helpful anywhere so this is something I came up with myself. and that worries me.

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-06-15T07:12:05+00:00Added an answer on June 15, 2026 at 7:12 am

    The is_valid() call will probably validate the individual fields correctly, but it might ignore other model validation, for example a unique_together statement or a custom clean method on one of the other models.

    I don’t think that checking is_valid() for multiple forms is that ugly. I’ve used it before, and immediately understand what you’re doing. However, I’ve never seen anyone define a form by grabbing a fields from another forms base_fields before. That doesn’t mean it won’t work, but it is unconventional.

    If you’re really concerned about it being ugly, you could do something like the following:

    my_forms = [form_part_number, form_part, form_order]
    if all(f.is_valid() for f in my_forms):
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.