mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #7539, #13067 -- Added on_delete argument to ForeignKey to control cascade behavior. Also refactored deletion for efficiency and code clarity. Many thanks to Johannes Dollinger and Michael Glassford for extensive work on the patch, and to Alex Gaynor, Russell Keith-Magee, and Jacob Kaplan-Moss for review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14507 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3ba3294c6b
commit
616b30227d
28 changed files with 850 additions and 608 deletions
|
@ -749,15 +749,20 @@ model (e.g., by iterating over a ``QuerySet`` and calling ``delete()``
|
|||
on each object individually) rather than using the bulk ``delete()``
|
||||
method of a ``QuerySet``.
|
||||
|
||||
When Django deletes an object, it emulates the behavior of the SQL
|
||||
constraint ``ON DELETE CASCADE`` -- in other words, any objects which
|
||||
had foreign keys pointing at the object to be deleted will be deleted
|
||||
along with it. For example::
|
||||
When Django deletes an object, by default it emulates the behavior of the SQL
|
||||
constraint ``ON DELETE CASCADE`` -- in other words, any objects which had
|
||||
foreign keys pointing at the object to be deleted will be deleted along with
|
||||
it. For example::
|
||||
|
||||
b = Blog.objects.get(pk=1)
|
||||
# This will delete the Blog and all of its Entry objects.
|
||||
b.delete()
|
||||
|
||||
.. versionadded:: 1.3
|
||||
This cascade behavior is customizable via the
|
||||
:attr:`~django.db.models.ForeignKey.on_delete` argument to the
|
||||
:class:`~django.db.models.ForeignKey`.
|
||||
|
||||
Note that ``delete()`` is the only ``QuerySet`` method that is not exposed on a
|
||||
``Manager`` itself. This is a safety mechanism to prevent you from accidentally
|
||||
requesting ``Entry.objects.delete()``, and deleting *all* the entries. If you
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue