0

I make comments on the site and when I fill out the form I send it to me gives an error The above exception (no such table: news_commentmodel) was the direct cause of the following exception. And shows an error in saving the form After filling out the form, all comments (data) should be shown below. I display them through the template. views.py

def ArticleDetailView(request, pk, tag_slug=None):
      tag = None
      if tag_slug:
        tag = get_object_or_404(Tag, slug=tag_slug)
      Articles.objects.filter(pk=pk).update(view=F('view') + 1)
      Articles.objects.all()
      article_details = Articles.objects.filter(pk=pk).first()

      if request.method == 'POST':
          comment_form = Comments(request.POST)
          comment_form.save()
      else:
          comment_form = Comments()

      commentss = CommentModel.objects.all()

      return render(request, 'news/post.html', {'article_details': article_details,
                                                'tag': tag,
                                                'comment_form': comment_form, 'comments': commentss,
                                                })

models.py

class CommentModel(models.Model):
    name = models.CharField(max_length=100)
    text = models.TextField(default='')
    dates = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-dates']

    def __str__(self):
        return self.name

forms.py

class Meta:
    model = CommentModel
    fields = ('name', 'text')

post.html

<form action="" method="post">
  {% csrf_token %}

   <div style=" margin-left: 35% ; border: 3px solid #4242A3; border-radius: 15px; width: 400px ; " > <br> <br>  {{ comment_form }}

     <br>

     <input type="submit" value="оставить коммент">

     <br>

   </div>

             {% if commentss %}
    {% for comment in commentss %}
    <div class="container" >
    <div class="panel panel-default" style="color: #4363A3 ;" id="Comment">
      <div style="color: #4363A3 ;"  class="panel-heading" id="CommentHead">
          <h1>{{ comment.name }}</h1>
      </div>
      <div class="panel-body" >
          <h3> {{ comment.text }}</h3>

        <br>
        <br>
        <br>

          <h3 align="right"> {{ comment.dates }}</h3>
      </div>
    </div>
    </div>
    {% endfor %}
  {% endif %}

</form>
NeIT
  • 145
  • 1
  • 9

0 Answers0