Here's a snip of my model:
class Comment(models.Model):
entry = models.ForeignKey('Entry')
name = models.CharField(max_length=100)
email = models.EmailField(max_length=200, blank=True)
website = models.URLField(verify_exists=True, blank=True)
body = models.TextField()
Here's what I have in my view:
if request.method == 'POST':
commentform = CommentForm(request.POST)
if commentform.is_valid():
commentform.save(commit=False)
commentform.entry = entry.id
commentform.save()
else:
commentform = CommentForm()
Once "commentform" validates I get an error when I run the last save()
method. Here's the error:
null value in column "entry_id" violates not-null constraint
But I'm assigning "entry_id" a value with this line:
commentform.entry = entry.id
I'm grabing the "entry" with this before the save() and I know for a
fact that "entry.id" is not null.
entry = Entry.objects.filter(publish_date__lte = datetime.now
()).order_by('-publish_date')[0]
The question is, why can't I append the "entry_id" value before the
commited save?
I've tried using "entry.pk" instead of "entry.id", and I've tried
using "commentform.entry_id" and "commentform.id" instead of
"commentform.entry". Still no luck, I get the same error every time.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---