-2

我正在关注需要一个最小的 Django 文件上传示例

每次上传时,列表都在增加,我如何删除对象数据,即Document: Document object通过 python shell 手动

>>> from myproject.myapp.models import Document

>>> Document.objects.all()

[<Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, 

>>> Document

  <class 'myproject.myapp.models.Document'>
4

2 回答 2

2

删除所有对象:-

Document.objects.all().delete()

删除满足某些过滤器的对象:-

Document.objects.filter(<your_filters>).delete()

删除对象但也要确保调用 django 信号(如果有):

for document in Document.objects.filter(<your_filters>):
    document.delete()
于 2013-09-22T12:10:30.503 回答
1
remove(obj1, obj2, ...)
    Removes the specified model objects from the related object set.

请参阅此处的文档:https ://docs.djangoproject.com/en/dev/topics/db/queries/

于 2013-09-22T02:10:42.670 回答