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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:39:21+00:00 2026-06-07T05:39:21+00:00

I need some help getting past a django error using inline forms. I can’t

  • 0

I need some help getting past a django error using inline forms. I can’t seem to figure this out. I could probably force-insert the eventID if I could figure out how to do that before it tries to validate.

When I submit my form I get an error: Hidden field (event): The inline foreign key did not match the parent instance primary key

Is there any way to make this code work?

The following code is supposed to let a teacher enrol multiple students for an event.

—— models.py ————

class Event(models.Model):
    title = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    time = models.DateTimeField()
    duration = models.DecimalField(max_digits=5, decimal_places=2)
    location = models.CharField(max_length=200)


# Customer is a parent, teacher, or school
class Customer(models.Model):
    event = models.ForeignKey(Event)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30) 
    address1 = models.CharField(max_length=60) 
    address2 = models.CharField(max_length=60, blank=True) 
    city = models.CharField(max_length=30) 
    state = models.CharField(max_length=2) 
    zipcode = models.CharField(max_length=5) 
    phone_number = models.CharField(max_length=30)
    email = models.EmailField()


# A customer can enroll several students for a single event.
class Attendee(models.Model):
    event = models.ForeignKey(Event)
    sponsor = models.ForeignKey(Customer)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30) 

—— forms.py ———–

class AttendeeForm(forms.ModelForm):
  event = forms.IntegerField(required=True, widget=forms.HiddenInput())

  class Meta:
    model = Attendee
    fields = ( 'event', 'last_name', 'first_name', 'gender', 'schoolYr', )
    #exclude = ('event', )
    #widgets = {
    #     'dtgPurchase' : DateTimeWidget(),
    #}

  def __init__(self, *args, **kwargs):
      super(AttendeeForm, self).__init__(*args, **kwargs)

——- views.py ———-

def register3(request, event_id):
  messages = []
  try:
    event = get_object_or_404(Event, id=event_id)  #Event ID is passed in here.
    AttendeeFormSet = inlineformset_factory(Event, Attendee, form=AttendeeForm, extra=1)
    #AttendeeFormSet = formset_factory(AttendeeForm)
    if request.method == 'POST':
      print "POST"
      formset = AttendeeFormSet(request.POST, request.FILES, prefix='attendees')
      #formset.save(commit=False)
      i=0
      for form in formset.forms:
         print "Form %s " % str(i)
         #  ??  Is is possible to set the event Here? 

      if formset.is_valid():
          attendees = formset.save_all()
          print "Yay!!!"   
          #return redirect('event_view', event_id=event.id)
      else:
          print "Invalid formset"

    else:   # is get method on first step
      formset = AttendeeFormSet(instance=event, prefix='attendees')
      print "Event: %s " % event

  except Event.DoesNotExist:
      raise Http404

  c = Context({
      'messages': messages,
      'event' : event,
      'attendees': formset,
  })
  return prepCxt(request, 'register3.html', c)    
  • 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-07T05:39:22+00:00Added an answer on June 7, 2026 at 5:39 am

    You may need to pass instance in POST processing as well.

    formset = AttendeeFormSet(request.POST, request.FILES, prefix='attendees', instance=event)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys i need some help here , im getting this error here at the
I need some help in getting this right, problem Write a function which takes
I'm currently using json-framework and need some help though parsing some JSON i'm getting
I need some help getting data from several tables. This is the tables I
this might be really simple, but just need some help in getting the syntax
I need some help with a binding error I'm getting from a style on
Hey all i am in need of some help getting my code working correctly
I need some help in understanding what is happening here .I am getting a
I need some help. Here's what I'm getting right now: img ref I need
Need some help to solve this. I have a gridview and inside the gridview

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.