20 lines
575 B
Python
20 lines
575 B
Python
from django import forms
|
|
|
|
from apps.comments.models import Comment
|
|
|
|
|
|
class CommentForm(forms.ModelForm):
|
|
honeypot = forms.CharField(required=False)
|
|
article_id = forms.IntegerField(widget=forms.HiddenInput)
|
|
parent_id = forms.IntegerField(required=False, widget=forms.HiddenInput)
|
|
|
|
class Meta:
|
|
model = Comment
|
|
fields = ["author_name", "author_email", "body"]
|
|
|
|
def clean_body(self):
|
|
body = self.cleaned_data["body"]
|
|
if not body.strip():
|
|
raise forms.ValidationError("Comment body is required.")
|
|
return body
|