python - Add optional fields to django's built-in comments app -


I want to add a thumb and counter thumb as comment areas and I called 'MyComment' in models.py Add two inteferer to a class. And I also use such forms.py:

Import from blog.models CommentForm Import MyComment class MyCommentForm (CommentForm): THUMBS_UP = forms .IntegerField () THUMBS_DOWN = forms.IntegerField () def get_comment_model (auto): return MyComment def get_comment_create_data (auto): data = super (MyCommentForm, self) .get_comment_create_data () data ['THUMBS_UP'] = self.cleaned_data ['THUMBS_UP'] Data ['THUMBS_DOWN'] = self.cleaned_data ['THUMBS_DOWN'] return data

After that, when I submit a comment, say THUMBS_UP And THUMBS_DOWN are required Not. How do I make them optional, just like the default field "user url"? Import django.contrib.comments.models from

  Comment class Mycomment (comment): thumbs_up = Model. Text after the integerField (default = 0) THUMBS_DOWN = models.IntegerField (default = 0)  

you

MyComment (comment): THUMBS_UP = models.IntegerField (default = 0) THUMBS_DOWN = models.IntegerField (default = 0) < Look for more information and change the method like this:

  class MyCommentForm: CommentForm: THUMBS_UP = forms.IntegerField (expected = false) THUMBS_DOWN = forms.IntegerField ( Expected = false)  

and get_comment_create_data Take

  def get_comment_create_data (auto): data = super (MyCommentForm, itself) .get_comment_create_data () data ['thumbs_up'] = Self.cleaned_data.get ('thumbs_up', 0) data ['Thumbs_down'] = self.cleaned_data.get ('thumbs_down', 0) Return Data  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -