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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:23:56+00:00 2026-05-20T14:23:56+00:00

I have a user facing form, which is generated from a model. The model

  • 0

I have a user facing form, which is generated from a model. The model has a foreign key to a site “Section.” When I submit the form it returns an IntegrityError (null value in column “section_id” violates not-null constraint). I thought the issue was straightforward until I started working on it. The bug only occurs on my development server (CentOS release 5.5 (Final)). I don’t have this issue on my local environment (Mac OS X 10.5.8).

I entered the python shell and examined the form object; I noticed the “section” field (form.fields.section) was missing on my dev env. Both the project code and django version are identical on my local and dev. Adding to my frustration is the fact that the user facing form does have a hidden “section” field, but when that data is posted to the view the form field no longer exists. Any insight into the cause of this bug would be greatly appreciated and save me from the expense of Rogaine.

Thanks in advance,
Chris.

Code:

views.py

def event_registration(request, slug):
    section = get_object_or_404(Section, section__slug=slug)
    parent_page = Page.objects.get(section=section, slug='overview')
    page = Page.objects.get(section=section, slug='events-registration')

    form = EventRegistrationForm(label_suffix='')
    submitted = False

    if request.POST.has_key('event'):
        form = EventRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            submitted = True

    context = RequestContext(request)
    return render_to_response('section/event_registration.html',
                            {
                                'section': section,
                                'page': page,
                                'form': form,
                                'submitted': submitted
                            },
                            context_instance=context)

forms.py

class EventRegistrationForm(better_forms.BetterModelForm):

    class Meta:
        model = EventRegistration
        fieldsets = [
                        ('Step 1', {
                            'fields': ['event', 'guests']
                        }),
                        ('Step 2', {
                            'fields': ['first_name', 'email', 'last_name', 'phone', 'school_name']
                        }),
                    ]

models.py

class EventRegistration(models.Model):
    section = models.ForeignKey(Theater, verbose_name=_('Section'), 
        help_text=_("The Site Section"))
    event = models.ForeignKey(Event, verbose_name=_('Event'))
    guests = models.IntegerField(_('Number of Guests?'))
    first_name = models.CharField(_('First Name'), max_length=100)
    last_name = models.CharField(_('Last Name'), max_length=100)
    email = models.CharField(_('E-Mail Address'), max_length=255)
    phone = PhoneNumberField(_('Daytime Phone Number'))
    school_name = models.CharField(_('School Name'), max_length=200, blank=True, null=True)
  • 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-20T14:23:56+00:00Added an answer on May 20, 2026 at 2:23 pm

    Try this for your view:

    def event_registration(request, slug):
        section = get_object_or_404(Section, section__slug=slug)
        parent_page = Page.objects.get(section=section, slug='overview')
        page = Page.objects.get(section=section, slug='events-registration')
    
        eventr = EventRegistration(section=section)
        submitted = False
    
        if request.method == 'POST':
            form = EventRegistrationForm(request.POST, instance=eventr)
            if form.is_valid():
                form.save()
                submitted = True
        else:
            form = EventRegistrationForm(label_suffix='', instance=eventr)
    
        context = {
                     'section': section,
                     'page': page,
                     'form': form,
                     'submitted': submitted
                  }
        return render_to_response('section/event_registration.html', context,
                                context_instance=RequestContext(request))
    

    edit:

    technically, if you had just changed

    form.save()
    to
    instance = form.save(commit=False)
    instance.section=section
    instance.save()
    

    that would have also worked. You needed to fill out the section field of the new EventRegistration before committing it to the db.

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

Sidebar

Related Questions

I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user interface in .net which needs to receive data from a
I have a User class which may or may not have an associated Department.
We would like to have user defined formulas in our c++ program. e.g. The
I have a user that want to be able to select a textbox and
I have several user controls, let's say A , B , C and D
I have a user script that would be much more useful if it could
I have a user control in a repeater that I need to pass data
I have a user reporting that when they use the back button to return
I have a user control that is pretty basic. It contains several TextBox controls,

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.