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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:22:28+00:00 2026-05-29T18:22:28+00:00

I need to create registration form for an event. Each person that register can

  • 0

I need to create registration form for an event. Each person that register can bring guests. I want to register everything in one page. To do that I use a view with 1 RegistrationForm and X GuestForms. In my models, I have a Registration and Guest class I used to create the two forms with ModelForm.

The problem is that a GuestForm is not required to be filled (you don’t have to bring guests).

def register_form(request):
  error = False
  if request.method == 'POST':
    register = RegistrationForm(request.POST, instance=Registration() )
    guests = [GuestForm(request.POST, prefix=str(x), instance=Guest()) for x in range(MAXGUESTS)]
    if register.is_valid():
        print("register is valid")

        for guest in guests:
            if guest.is_valid():
                print("guest is valid")
            else:
                print("guest is not valid") # always when empty form
                error = True
    else:
        print("register is not valid")
        error = True

    if not error:
       ... # save the form in the database

  register = RegistrationForm(instance=Registration())
  guests = [GuestForm(prefix=str(x), instance=Guest()) for x in range(MAXGUESTS)]
  return render_to_response('register.html',{
        'form': register,
        'max_guests': MAXGUESTS,
        'guests': guests,
        'error': error,
        })

So I need to set a form as optional and be able to differentiate when the whole form is empty and when there is an error. Any idea how ?

Thank you


Solution

def register_form(request):
  GuestFormSet = modelformset_factory(Guest, exclude=('register',))
  error = False
  if request.method == 'POST':
    register = RegistrationForm(request.POST, instance=Registration() )
    guests = GuestFormSet(request.POST)
    if register.is_valid():
        print("register is valid")

        for guest in guests:
            if guest.is_valid():
                print("guest is valid") # even if some forms are empty
            else:
                print("guest is not valid")
                error = True
    else:
        print("register is not valid")
        error = True

    if not error:
       ... 
       # save the form in the database
       return something

  else:
      register = RegistrationForm(instance=Registration())
      guests = GuestFormSet(queryset=Guest.objects.none())
  return render_to_response('register.html',{
        'form': register,
        'max_guests': MAXGUESTS,
        'guests': guests,
        'error': error,
        })
  • 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-29T18:22:32+00:00Added an answer on May 29, 2026 at 6:22 pm

    You can use a model formset for your guest forms. It can distinguish between empty and invalid forms.

    https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#model-formsets

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

Sidebar

Related Questions

I need to create some simple form that will be use to registration a
I want to put 2 fields on user registration form, /customer/account/create/. Those fields are
I've created a registration form control for a Sitecore site that will create a
Im about to create a registration form for my website. I need to check
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
Am I correct in my understanding that I can only pass-through one custom variable
I'm creating a registration form and want to check to see if an email
I needed to create a custom select list for the user registration page 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.