Skip to content

Commit

Permalink
Merge pull request #640 from jdufresne/on-delete
Browse files Browse the repository at this point in the history
Include on_delete in all TreeForeignKey examples in docs
  • Loading branch information
craigds committed Apr 15, 2018
2 parents 7ffa84e + 7108ae3 commit 631a530
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Start with a basic subclass of MPTTModel, something like this::

class Genre(MPTTModel):
name = models.CharField(max_length=50, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children', db_index=True)

You must define a parent field which is a ``ForeignKey`` to ``'self'``. Recommended: use ``TreeForeignKey``. You can
call it something different if you want - see `Model Options`_ below.
Expand All @@ -42,7 +42,7 @@ To change the names, create an ``MPTTMeta`` class inside your class::

class Genre(MPTTModel):
name = models.CharField(max_length=50, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children', db_index=True)

class MPTTMeta:
level_attr = 'mptt_level'
Expand All @@ -58,7 +58,7 @@ The available options for the MPTTMeta class are:
Users are responsible for setting this field up on the model class,
which can be done like so::

parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children', db_index=True)

For the following four arguments, if fields with the given names do not
exist, they will be added to the model dynamically:
Expand Down Expand Up @@ -116,7 +116,7 @@ You can't subclass MPTTModel without modifying the Group source. Instead, you ca
from django.contrib.auth.models import Group

# add a parent foreign key
TreeForeignKey(Group, blank=True, null=True, db_index=True).contribute_to_class(Group, 'parent')
TreeForeignKey(Group, on_delete=models.CASCADE, blank=True, null=True, db_index=True).contribute_to_class(Group, 'parent')

mptt.register(Group, order_insertion_by=['name'])

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Start with a basic subclass of MPTTModel, something like this::

class Genre(MPTTModel):
name = models.CharField(max_length=50, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children', db_index=True)

class MPTTMeta:
order_insertion_by = ['name']
Expand Down

0 comments on commit 631a530

Please sign in to comment.