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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:36:19+00:00 2026-06-03T01:36:19+00:00

Ok, that question I’m sure was confusing. Imagine we have this models: class Phone(models.Model):

  • 0

Ok, that question I’m sure was confusing. Imagine we have this models:

class Phone(models.Model):
    serial = models.CharField(max_length=13, unique=True)
    model = models.CharField(max_length=4, choices=MODELOS)

class Contract(models.Model):
    number = models.IntegerField()
    phone = models.OneToOneField(Phone)
    notes = models.TextField(blank=True, null=True)
    sign = models.BooleanField(default=False)

I need to make a form which can have input for all the fields in those models. In one single page I need to specify the phone’s serial and model and the contract’s number, notes and sign. The phone field should be the one created in the same moment. How would I manage to do this?

Thank you!

  • 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-03T01:36:20+00:00Added an answer on June 3, 2026 at 1:36 am

    As ilvar suggests, define two modelforms

    class PhoneForm(forms.ModelForm):
        class Meta:
            model = Phone
    
    class ContractForm(forms.ModelForm):
        class Meta:
            model = Contract
            exclude = ('phone',)
    
    def add(request):
       ...
       if request.method == 'POST':
           phone_form = PhoneForm(request.POST)
           contract_form = ContractForm(request.POST)
           if phone_form.is_valid() and contract_form.is_valid():
               phone = phone_form.save()
               contract = contract_form.save(commit=False)
               contract.phone = phone
               contract.save()
       ...
    

    Also, just curious why you use OneToOneField instead of ForeignKey or ManyToManyField, anyway.

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

Sidebar

Related Questions

I'm not sure how to formulate that question but: you have a webpage the
I little while back I posted this question . I have updated that question
This Question arises from a Q&A here I have some doubts that i think
This question is sort of a sequel to that question. When we want to
I'm not sure really how to ask that question.. hopefully my explanation will clarify:
Sorry if that question is confusing, I'm self-learning javascript. I'm dynamically generating image thumbnails
Since this question tells me that SoapHttpClientProtocol is not thread safe. And, my real
This question is a spin-off/evolution of this question . (That question got marked as
This may look like the recent question that asked why Perl doesn't allow one-liners
This question is a dual of Constructor with by-value parameter & noexcept . 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.