Django Comments: Want to remove user URL, not expand the model. How to?

前端 未结 3 981
礼貌的吻别
礼貌的吻别 2020-12-31 08:36

I\'m totally understanding the documentation on expanding the Comments app in Django, and really would like to stick with the automatic functionality but...

3条回答
  •  青春惊慌失措
    2020-12-31 08:44

    My quick and dirty solution: I made the the 'email' and 'url' fields hidden fields, with an arbitrary value to get rid of 'this field is required' errors.

    It's not elegant, but it's quick and I didn't have to subclass CommentForm. All the work of adding comments was done in the template, which is nice. It looks like this (warning: not tested, since it's a simplified version of my actual code):

    {% get_comment_form for entry as form %}
    
    
    {% csrf_token %} {% for field in form %} {% if field.name != 'email' and field.name != 'url' %}

    {{field.label}} {{field}}

    {% endif %} {% endfor %}

提交回复
热议问题