Thanks to James Murty for his work on an alternate patch.
This commit is contained in:
parent
8bdfabed65
commit
211486f3ab
|
@ -55,7 +55,7 @@ def get_candidate_relations_to_delete(opts):
|
||||||
# The candidate relations are the ones that come from N-1 and 1-1 relations.
|
# The candidate relations are the ones that come from N-1 and 1-1 relations.
|
||||||
# N-N (i.e., many-to-many) relations aren't candidates for deletion.
|
# N-N (i.e., many-to-many) relations aren't candidates for deletion.
|
||||||
return (
|
return (
|
||||||
f for f in opts.get_fields(include_hidden=True)
|
f for f in opts.concrete_model._meta.get_fields(include_hidden=True)
|
||||||
if f.auto_created and not f.concrete and (f.one_to_one or f.one_to_many)
|
if f.auto_created and not f.concrete and (f.one_to_one or f.one_to_many)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,12 @@ class ConcreteModel(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConcreteModelSubclass(ConcreteModel):
|
class ProxyModel(ConcreteModel):
|
||||||
|
class Meta:
|
||||||
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
|
class ConcreteModelSubclass(ProxyModel):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.utils._os import upath
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
ConcreteModel, ConcreteModelSubclass, ConcreteModelSubclassProxy,
|
ConcreteModel, ConcreteModelSubclass, ConcreteModelSubclassProxy,
|
||||||
|
ProxyModel,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,3 +44,10 @@ class MultiTableInheritanceProxyTest(TestCase):
|
||||||
self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
|
self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
|
||||||
self.assertEqual(0, ConcreteModelSubclass.objects.count())
|
self.assertEqual(0, ConcreteModelSubclass.objects.count())
|
||||||
self.assertEqual(0, ConcreteModel.objects.count())
|
self.assertEqual(0, ConcreteModel.objects.count())
|
||||||
|
|
||||||
|
def test_deletion_through_intermediate_proxy(self):
|
||||||
|
child = ConcreteModelSubclass.objects.create()
|
||||||
|
proxy = ProxyModel.objects.get(pk=child.pk)
|
||||||
|
proxy.delete()
|
||||||
|
self.assertFalse(ConcreteModel.objects.exists())
|
||||||
|
self.assertFalse(ConcreteModelSubclass.objects.exists())
|
||||||
|
|
Loading…
Reference in New Issue