How to remove all of the data in a table using Django

后端 未结 8 1755
执笔经年
执笔经年 2020-12-12 21:12

I have two questions:

  1. How do I delete a table in Django?
  2. How do I remove all the data in the table?

This is my code, which is not succe

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 21:56

    Use this syntax to delete the rows also to redirect to the homepage (To avoid page load errors) :

    def delete_all(self):
      Reporter.objects.all().delete()
      return HttpResponseRedirect('/')
    

提交回复
热议问题