如何解决“操作错误;无此表:main.blog_post__old”?

时间:2019-01-20 11:41:18

标签: django python-3.x django-models django-views

我需要从数据库中删除现有条目。为了删除我正在使用基于类的视图,并使用方法super()。delete(* args,** kwargs),但是我反复遇到相同的错误..有什么办法可以解决它吗?

views.py文件,删除视图

class DeletePost(LoginRequiredMixin, generic.DeleteView):
    model = models.Post
    success_url = reverse_lazy("blog:all")

    def get_queryset(self):
        queryset = super().get_queryset()
        return queryset.filter(user_id=self.request.user.id)

    def delete(self, *args, **kwargs):
        messages.success(self.request, "Post Deleted")
        return super().delete(*args, **kwargs)

models.py文件

 User = get_user_model()


class Post(models.Model):
 user=models.ForeignKey(User,related_name='posts',on_delete=models.CASCADE)
 title = models.CharField(max_length=150, default=('New Post'))
 created_at = models.DateTimeField(auto_now=True)
 message = models.TextField()

 def __str__(self):
    return self.title

 def get_absolute_url(self):
    return reverse('blog:all')

  class Meta():
    ordering = ['-created_at']
    unique_together = ('user','message')
{% extends "blog/blog_base.html" %}


{% block post_content %}
  <h3>Are you sure you want to delete this post?</h3>


   {% include "blog/_blog_detail.html" with post=object hide_delete=True %}


<form method="POST">
    {% csrf_token %}
    <input type="submit" value="Confirm Delete">
    <a href="{% url 'blog:single' username=user.username pk=object.pk %}">Cancel</a>
</form>

{% endblock %}

0 个答案:

没有答案