Basically I am doing the following:

  u=User.objects.get(username="kamilski81")
  goal = Goal(user=u)
  form = GoalForm(request.POST, goal)

and get this error:

(1048, "Column 'user_id' cannot be null")

FROM THE front-end...

Kamil


On Feb 5, 10:43 pm, Dylan Evans <dy...@contentfree.info> wrote:
> user = User.objects.get(username__exact='bob')
> Works fine for me, you may want to try get since it will throw an exception
> if there is no matching user. Then you know the problem is elsewhere.
>
>
>
> On Sat, Feb 6, 2010 at 11:30 AM, kamilski81 <kamilsk...@gmail.com> wrote:
> > I would like to save a form by doing the following:
>
> > #Goal has a User ForeignKey (django.contrib.auth.models.User)
> > ---------
> > class GoalForm(ModelForm):
> >    class Meta:
> >        model = Goal
> > -----------
> > class Goal(models.Model):
> >    user = models.ForeignKey(User, editable=False)
> > ----------
> > view.py =>
> > from django.contrib.auth.models import User
> > .
> > .
> > QuerySetUser = User.objects.filter(username__icontains='myusername')
> >  goal = Goal(user=QuerySetUser[0])
> >  form = GoalForm(request.POST, goal)
> > .
> > But i'm getting the error :
> > (1048, "Column 'user_id' cannot be null")
>
> > Any idea how I can pull a user from the database and save a goal? Or
> > set the user_id?
>
> > --
> > 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<django-users%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> "The UNIX system has a command, nice ... in order to be nice to the other
> users. Nobody ever uses it." - Andrew S. Tanenbaum

-- 
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