mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #22998 -- Updated the fast_delete logic for GFKs
This commit is contained in:
parent
28efafa24c
commit
6e2b82fdf6
3 changed files with 41 additions and 4 deletions
|
@ -4,6 +4,7 @@ from django.contrib.contenttypes.fields import (
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.db.models.deletion import ProtectedError
|
||||
|
||||
|
||||
__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
|
||||
|
@ -192,3 +193,26 @@ class D(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ('id',)
|
||||
|
||||
|
||||
# Ticket #22998
|
||||
|
||||
class Node(models.Model):
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content = GenericForeignKey('content_type', 'object_id')
|
||||
|
||||
|
||||
class Content(models.Model):
|
||||
nodes = GenericRelation(Node)
|
||||
related_obj = models.ForeignKey('Related', on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class Related(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
def prevent_deletes(sender, instance, **kwargs):
|
||||
raise ProtectedError("Not allowed to delete.", [instance])
|
||||
|
||||
models.signals.pre_delete.connect(prevent_deletes, sender=Node)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue