Hi,

I've decided to play a little more seriously with Django and as many 
other people I
begun creating a simple blog application. I've encountered some issues when
displaying the comments form, where users are able to add comments to a 
blog post.

I'm creating the form by extending django.forms.ModelForm using as a model a
Comment class which has a ForeignKey to a Post model. When rendered, the
form includes a SELECT widget for selecting the blog post to which the 
comment
belongs, but the post is already known. So how do I specify the post id 
so that
the form renders a hidden field with the id as a value. Here's what I 
have so far:

# models
class Post(models.Model):
     title = models.CharField(max_length=256)
     slug = models.SlugField(max_length=256)
     content = models.TextField()
     published = models.DateTimeField(auto_now_add=True)
     tags = models.ManyToManyField(Tag)

     def __unicode__(self):
         return self.title

class Comment(models.Model):
     post = models.ForeignKey(Post, related_name='comments')
     author = models.CharField(max_length=256)
     email = models.EmailField(max_length=256)
     website = models.URLField(max_length=256)
     content = models.TextField()
     published = models.DateTimeField(auto_now_add=True)

     def __unicode__(self):
         return self.

# form
class CommentForm(ModelForm):
     class Meta:
         model = Comment
         exclude = ('post',)


Any help greatly appreciated.

-- 
Ionut G. Stan
I'm under construction  |  http://igstan.blogspot.com/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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