Hi Daniel, thanks for looking at this!

Here is my views.py code related to this:

@login_required
def wine_add_page(request):
  if request.method == 'POST':
    form = WineAddForm(request.POST)
    if form.is_valid():
      #create or get dummy wine
      wine, dummy = Wine.objects.get_or_create(
        wine_name=form.cleaned_data['wine_name']
      )

      #update wine_name
      winerater.wine_name = form.cleaned_data['title']
      #if the bookmark is being updated, clear old tag list
      if not created:
        winerater.tag_set.clear()
      #create new tage list
      tag_names = form.cleaned_data['tags'].split()
      for tag_name in tag_names:
        tag, dummy = Tag.objects.get_or_create(name=tag_name)
        wnerater.tag_set.add(tag)
        #save wine to DB
      winerater.save()
      return HttpResponseRedirect(
        '/user/%s/' % request.user.username
      )
  else:
    form = WineAddForm()
  variables = RequestContext(request, {
    'form': form
  })
  return render_to_response('wine_add.html', variables)


HTH

-Ben

On Sep 13, 11:07 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sep 13, 5:48 pm, keynesiandreamer <keynesiandr...@gmail.com> wrote:
>
>
>
> > Howdy,
>
> > I am still new to Django and have been working with forms.
>
> > Currently I a getting an error that says a field can't be NULL, even
> > though I have entered data into it. Weird!
>
> > Error:
> > IntegrityError at /save/
>
> > winerater_wine.alcohol may not be NULL
>
> > Request Method:         POST
> > Request URL:    http://localhost:1100/save/
> > Exception Type:         IntegrityError
> > Exception Value:
>
> > winerater_wine.alcohol may not be NULL
>
> > Exception Location:     /Library/Python/2.6/site-packages/django/db/
> > models/query.py in get_or_create, line 343
> > Python Executable:      /usr/bin/python
> > Python Version:         2.6.1
>
> > Here the code for model/form issue:
>
> > From my forms.py file:
> > class WineAddForm(forms.Form):
> >   wine_name = forms.CharField(
> >     label = u'Wine Name:',
> >     widget=forms.TextInput(attrs={'size': 30})
> >   )
> >   wine_kind = forms.ChoiceField(choices=WINE_KIND)
> >   wine_year = forms.CharField(widget=forms.Select(choices=WINE_YEAR),
> > required=False)
> >   alcohol = forms.DecimalField(max_digits=3,
> >     decimal_places=1,
> >     widget=forms.TextInput(attrs={"size": 5}))
>
> > class Wine(models.Model):
> >   wine_name = models.CharField(max_length=60, unique=True)
> >   wine_kind = models.CharField(max_length=9)
> >   varietal = models.CharField(max_length=25)
> >   wine_year = models.DateField(max_length=4, null=True)
> >   alcohol = models.FloatField()
>
> > I apologize in advance if this code is completely bass-ackwards, but
> > you have to start some where... I did search on this but wasn't able
> > to resolve it.
>
> > Thanks in advance for any help!
>
> You're not using a ModelForm here, so presumably you have some code in
> your view to create a Wine object from the form submission. Can you
> show this code?
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to