Well, the problem with built in comments framework is that I need few more
fields in comments.
What I created is:
MODEL:
class Comment(models.Model):
name = models.CharField(max_length = 30)
body = models.CharField(max_length = 2000)
article = models.ForeignKey(Article)
def __unicode__(self):
return u"%s" %(self.name)
FORM:
class CommentForm(forms.Form):
'''
The Register form is created to deal with registration process
check if data is clean and passwords match each other
'''
username = forms.CharField(label='Name', max_length=30)
body = forms.CharField(required = True,
label = 'Comment Body',
widget=forms.Textarea)
def clean_body(self):
if 'body' in self.cleaned_data:
body = self.cleaned_data['body']
if not re.search(r'^\w+$', username):
raise forms.ValidationError('Error: body can contains \
only alphanumeric characters')
VIEW:
def article_page(request, page_name):
article = get_object_or_404(models.Article, url = page_name)
articles_list =
models.Article.objects.exclude(is_published__exact="0").order_by("-pub_date")
if request.method == 'POST':
form = CommentForm(request.POST)
# Creating a comment
if form.is_valid():
comment = Comment(
name = from.cleaned_data['name'],
body = form.cleaned_data['body'],
article = ????
)
return render_to_response('article.html',
{'section': article.title,
'article' : article,
'articles' : articles_list}
)
Not sure how to fill the article field :(
Thanks in advance,
Oleg
On Tue, May 12, 2009 at 1:01 PM, Daniel Roseman <
[email protected]> wrote:
>
> On May 12, 10:51 am, Oleg Oltar <[email protected]> wrote:
> > Hi!
> > I am running small blog-styled information site. Which contains articles
> > added via admin application
> > Now I am trying to add possibility to add comments, so I defined a
> comment
> > Model (which contains Foreign Key to article object, and few text
> fields),
> > also defined forms.
> >
> > Can you please explain how should I create a comment object in view?
> (After
> > processing data from form). I don't understand where can I get, the
> article
> > name (id, guid or something) to link article and comment
> >
> > Thanks in advance,
> > Oleg
>
> Firstly, have you investigated the built-in comment app? It's quite
> full-featured, and may do everything you want.
>
> Assuming you've decided that your own model is the way to go, the
> answer to your question will depend on the way you've defined your
> form and view. Presumably the comment form is displayed at the bottom
> of an article page, so you'll already have the ID of the article - so
> I don't really understand what your issue is. Perhaps you could post
> the code you have so far?
> --
> DR.
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---