Comments form customization

18 views
Skip to first unread message

Fabio Natali

unread,
Feb 13, 2012, 4:43:41 AM2/13/12
to django...@googlegroups.com
Hi everybody,

I am using comments app from contrib in Django 1.3.

In my website I let only authenticated users to leave a comment so I'd
like to get rid of those "name", "email" and "url" fields that come with
the standard comment form. Indeed, I already know the name and email of
current logged user, there's no need for the user to submit his/her name
and email again.

So, I'd just like a FK field to the user that left the comment. More of
that, I would like that field to be automatically populated while the
user submit the comment.

Could you give me some hints for such customization?

Thank you very much,
Fabio.

--
Fabio Natali

Vovk Donets

unread,
Feb 13, 2012, 4:52:49 AM2/13/12
to django...@googlegroups.com
It's not really great solution, but maybe it will give you a hint: you can add/remove fileds to the form on the fly. And for not logged in users show all fields, but for authenticated only subset of the all form fields. 

2012/2/13 Fabio Natali <fa...@fnstudio.it>

--
Vovk Donets
 python developer


Fabio Natali

unread,
Feb 13, 2012, 5:12:06 AM2/13/12
to django...@googlegroups.com
On 02/13/2012 10:52 AM, Vovk Donets wrote:
> It's not really great solution, but maybe it will give you a hint: you
> can add/remove fileds to the form on the fly. And for not logged in
> users show all fields, but for authenticated only subset of the all form
> fields.

Ehi Vladimir, thank you for your quick reply!

I found a couple of interesting links.

http://mitchfournier.com/2010/08/12/customizing-django-comments-remove-unwanted-fields/
http://stackoverflow.com/questions/1456267/django-comments-want-to-remove-user-url-not-expand-the-model-how-to/4766543#4766543

The first deals with writing your own comment templates, so to remove
unnecessary fields (name, url, email).

The latter deals with writing your own custom comment form, no need to
hack template stuff. This looks nicer to me, I think I'll try it first.

Vladimir, is that the approach you meant?

I am still not sure this is the best solution for me. So, those of you
who are listening, if you have any further advice/hint, don't hesitate
to email me! :-)

Cheers, Fabio.

--
Fabio Natali

coded kid

unread,
Feb 13, 2012, 5:33:36 AM2/13/12
to Django users
Hey Fabio,
How do you get your comment form to display? Been fighting with this
for the past 5hrs. Please any idea? Thanks.

On Feb 13, 11:12 am, Fabio Natali <fa...@fnstudio.it> wrote:
> On 02/13/2012 10:52 AM, Vovk Donets wrote:
>
> > It's not really great solution, but maybe it will give you a hint: you
> > can add/remove fileds to the form on the fly. And for not logged in
> > users show all fields, but for authenticated only subset of the all form
> > fields.
>
> Ehi Vladimir, thank you for your quick reply!
>
> I found a couple of interesting links.
>
> http://mitchfournier.com/2010/08/12/customizing-django-comments-remov...http://stackoverflow.com/questions/1456267/django-comments-want-to-re...

Fabio Natali

unread,
Feb 13, 2012, 8:49:41 AM2/13/12
to django...@googlegroups.com
On 02/13/2012 11:44 AM:
> Yeah, thanks for the reply. I followed the doc but it's not working
> for me.
[...]

Hi there!

If you have an object my_object passed by your view to your template, I
think you can write:

{% load comments %}
{% get_comment_count for my_object as comment_count %}
{% get_comment_list for my_object as comment_list %}
{% get_comment_form for my_object as form %}

and then you can:

<form action="{% comment_form_target %}" method="post">
{% csrf_token %}
{{ form }}
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Post">
<input type="submit" name="preview" value="Preview">
</td>
</tr>
</form>

Let me know it that's of any help. In case, write me what kind of error
you get. Also, I can pass you my source code so you can have an example.

Fabio Natali

unread,
Feb 13, 2012, 8:50:19 AM2/13/12
to django...@googlegroups.com
On 02/13/2012 11:12 AM, Fabio Natali wrote:
> http://stackoverflow.com/questions/1456267/django-comments-want-to-remove-user-url-not-expand-the-model-how-to/4766543#4766543

This link worked fine for me. :-)

--
Fabio Natali FNstudio
http://fnstudio.it
fabio_natali@skype

Reply all
Reply to author
Forward
0 new messages