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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:45:01+00:00 2026-05-20T07:45:01+00:00

Well, it may actually be a simple case but I’m having a tough time

  • 0

Well, it may actually be a simple case but I’m having a tough time figuring it out.

I have two user registration funnels (corporate & everyone else). When a corporate user creates a User instance through my registration form, I would also like them to input secondary forms that create related instances (based on the Website and Organization_Contact models).

I know how to solve this by making additional synchronous or asynchronous requests, but I’d like the user to fill out the three forms and submit with one click.

My issue here is that the other two forms rely on a User foreign key as a field. I’ve made that field “null=True, blank=True” so that I can validate and save the forms without the foreign key, but I ultimately want to add that key to both model instances.

I thought that I could validate the three forms, save the UserForm, and then use a model queryset to return the new User.id (all in one view). I would then add that user_id value to the other two form dictionaries (WebsiteForm and Organization_ContactForm).

It would work as so:

def register_company(request):
    if request.method=='POST'
       uform=UserCreationForm(request.POST, prefix='user')
       sform=SiteForm(request.POST, prefix='site')
       oform=OrgForm(request.POST, prefix='site')
       if uform.is_valid() and sform.is_valid() and oform.is_valid():
            uform.save()
            user=User.objects.get(email__iexact=uform.cleaned_data['email'])
            uid=unicode(user.id)
       #now I'd add uid back into the SiteForm and Orgform dictionaries and then save both instances              

Problems:
1) Not sure if I can save a modelform and then return that model instance as a queryset in a single view

2)I say that I’m not sure because I couldn’t get passed the problem of trying to pass a variable to the queryset.

The get manager method seems to not accept a variable there. I assume as much because I passed an equivalent hardcoded string and it worked.

Ok, so I was thinking about creating a new manager method (email) which accepted a variable argument (the cleaned email field) and then retrying the process of saving one modelform, retrieving the model id data, and saving the other modelforms.

I also thought that I might be able to handle this issue through a post save signal.

Just general direction here would be really helpful. I need a starting point.

  • 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-20T07:45:02+00:00Added an answer on May 20, 2026 at 7:45 am

    Are these all ModelForms?

    if request.method=='POST'
       uform=UserCreationForm(request.POST, prefix='user')
       sform=SiteForm(request.POST, prefix='site')
       oform=OrgForm(request.POST, prefix='site')
       if uform.is_valid() and sform.is_valid() and oform.is_valid():
            # save returns the object 
            user = uform.save()
    
            # commit = false doesn't save to DB.
            site = sform.save(commit=False)
            site.user = user
            site.save()
    
            org = oform.save(commit=False)
            org.user = user
            org.save()
    

    Update regarding comments: Why spread this form saving logic around into multiple areas and files (signals, form save) when you can do it in one place?

    The code is more readable, and you even save lines of code. Unless it’s going to be used globally.

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

Sidebar

Related Questions

Well... simple question, right? But with no so simple answers. In firefox i use
Well, it seems simple enough, but I can't find a way to add a
This may have been asked already, but I can't find it, so here goes.
hope all of you doing well. I have small question in C#.Net. actually i
Well the subject is the question basically. Are there any version control systems out
Well, after a long time writing .net programs in C# I started to feel
Well, this is my first post here and really enjoying the site. I have
well i have this messages table with sample values like these: msg_id recipient_id read
Actually I have a CGI form which consists of textfields and I need a
This may sound like a SuperUser issue, but I wrote the page in question

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.