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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.