-2

i am following Need a minimal Django file upload example

with each upload, list is increasing, how i can delete object data i.e Document: Document object manually through 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'>
Community
  • 1
  • 1
ashir nasir
  • 207
  • 2
  • 6
  • 11

2 Answers2

2

Delete all the objects :-

Document.objects.all().delete()

Delete objects satisfying some set of filters :-

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

Deleting objects but also ensuring that your django signals are invoked (if any):

for document in Document.objects.filter(<your_filters>):
    document.delete()
Siddharth Srivastava
  • 1,059
  • 1
  • 10
  • 22
1
remove(obj1, obj2, ...)
    Removes the specified model objects from the related object set.

See documentation here: https://docs.djangoproject.com/en/dev/topics/db/queries/

Mingyu
  • 31,751
  • 14
  • 55
  • 60
  • nothing works, i tried different combinations. Document.objects.remove(), remove(Document), remove(Document.objects.all()). please help – ashir nasir Sep 22 '13 at 10:48