Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Form Field missing on save
    primarykey
    data
    text
    <p>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). </p> <p>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.</p> <p>Thanks in advance, Chris. </p> <p>Code:</p> <p>views.py</p> <pre><code>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) </code></pre> <p>forms.py</p> <pre><code>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'] }), ] </code></pre> <p>models.py</p> <pre><code>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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload