Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14599 -- Added documentation for QuerySet.delete() in the Quer…

…ySet API reference. Thanks to abeld for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14505 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3ba3294c6b5ad413731223a9e46064a8e132acd2 1 parent 60ad315
Carl Meyer authored November 09, 2010

Showing 1 changed file with 31 additions and 0 deletions. Show diff stats Hide diff stats

  1. 31  docs/ref/models/querysets.txt
31  docs/ref/models/querysets.txt
@@ -1246,6 +1246,37 @@ The ``update()`` method does a bulk update and does not call any ``save()``
1246 1246
 methods on your models, nor does it emit the ``pre_save`` or ``post_save``
1247 1247
 signals (which are a consequence of calling ``save()``).
1248 1248
 
  1249
+``delete()``
  1250
+~~~~~~~~~~~~~~~~~~~~
  1251
+
  1252
+.. method:: delete()
  1253
+
  1254
+Performs an SQL delete query on all rows in the :class:`QuerySet`. The
  1255
+``delete()`` is applied instantly. You cannot call ``delete()`` on a
  1256
+:class:`QuerySet` that has had a slice taken or can otherwise no longer be
  1257
+filtered.
  1258
+
  1259
+For example, to delete all the entries in a particular blog::
  1260
+
  1261
+    >>> b = Blog.objects.get(pk=1)
  1262
+
  1263
+    # Delete all the entries belonging to this Blog.
  1264
+    >>> Entry.objects.filter(blog=b).delete()
  1265
+
  1266
+Django emulates the SQL constraint ``ON DELETE CASCADE`` -- in other words, any
  1267
+objects with foreign keys pointing at the objects to be deleted will be deleted
  1268
+along with them.  For example::
  1269
+
  1270
+    blogs = Blog.objects.all()
  1271
+    # This will delete all Blogs and all of their Entry objects.
  1272
+    blogs.delete()
  1273
+
  1274
+The ``delete()`` method does a bulk delete and does not call any ``delete()``
  1275
+methods on your models. It does, however, emit the
  1276
+:data:`~django.db.models.signals.pre_delete` and
  1277
+:data:`~django.db.models.signals.post_delete` signals for all deleted objects
  1278
+(including cascaded deletions).
  1279
+
1249 1280
 .. _field-lookups:
1250 1281
 
1251 1282
 Field lookups

0 notes on commit 3ba3294

Please sign in to comment.
Something went wrong with that request. Please try again.