Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -280,6 +280,7 @@ answer newbie questions, and generally made Django that much better: Eric Moritz <http://eric.themoritzfamily.com/> mrmachine <real.human@mrmachine.net> Robin Munn <http://www.geekforgod.com/> James Murty msundstr Robert Myers <myer0052@gmail.com> Nebojša Dorđević Loading django/db/models/query.py +3 −1 Original line number Diff line number Diff line Loading @@ -836,7 +836,9 @@ def delete_objects(seen_objs): update_query = sql.UpdateQuery(cls, connection) for field in cls._meta.fields: if field.rel and field.null and field.rel.to in seen_objs: if (field.rel and field.null and field.rel.to in seen_objs and filter(lambda f: f.column == field.column, field.rel.to._meta.fields)): update_query.clear_related(field, pk_list) # Now delete the actual data. Loading tests/regressiontests/queries/models.py +28 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,19 @@ class CustomPk(models.Model): class Related(models.Model): custom = models.ForeignKey(CustomPk) # An inter-related setup with a model subclass that has a nullable # path to another model, and a return path from that model. class Celebrity(models.Model): name = models.CharField("Name", max_length=20) greatest_fan = models.ForeignKey("Fan", null=True, unique=True) class TvChef(Celebrity): pass class Fan(models.Model): fan_of = models.ForeignKey(Celebrity) __test__ = {'API_TESTS':""" >>> t1 = Tag.objects.create(name='t1') Loading Loading @@ -836,6 +849,21 @@ related via ForeignKeys. >>> len(Note.objects.order_by('extrainfo__info').distinct()) 3 Bug #7778 - Model subclasses could not be deleted if a nullable foreign key relates to a model that relates back. >>> num_celebs = Celebrity.objects.count() >>> tvc = TvChef.objects.create(name="Huey") >>> Celebrity.objects.count() == num_celebs + 1 True >>> f1 = Fan.objects.create(fan_of=tvc) >>> f2 = Fan.objects.create(fan_of=tvc) >>> tvc.delete() # The parent object should have been deleted as well. >>> Celebrity.objects.count() == num_celebs True """} # In Python 2.3, exceptions raised in __len__ are swallowed (Python issue Loading Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -280,6 +280,7 @@ answer newbie questions, and generally made Django that much better: Eric Moritz <http://eric.themoritzfamily.com/> mrmachine <real.human@mrmachine.net> Robin Munn <http://www.geekforgod.com/> James Murty msundstr Robert Myers <myer0052@gmail.com> Nebojša Dorđević Loading
django/db/models/query.py +3 −1 Original line number Diff line number Diff line Loading @@ -836,7 +836,9 @@ def delete_objects(seen_objs): update_query = sql.UpdateQuery(cls, connection) for field in cls._meta.fields: if field.rel and field.null and field.rel.to in seen_objs: if (field.rel and field.null and field.rel.to in seen_objs and filter(lambda f: f.column == field.column, field.rel.to._meta.fields)): update_query.clear_related(field, pk_list) # Now delete the actual data. Loading
tests/regressiontests/queries/models.py +28 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,19 @@ class CustomPk(models.Model): class Related(models.Model): custom = models.ForeignKey(CustomPk) # An inter-related setup with a model subclass that has a nullable # path to another model, and a return path from that model. class Celebrity(models.Model): name = models.CharField("Name", max_length=20) greatest_fan = models.ForeignKey("Fan", null=True, unique=True) class TvChef(Celebrity): pass class Fan(models.Model): fan_of = models.ForeignKey(Celebrity) __test__ = {'API_TESTS':""" >>> t1 = Tag.objects.create(name='t1') Loading Loading @@ -836,6 +849,21 @@ related via ForeignKeys. >>> len(Note.objects.order_by('extrainfo__info').distinct()) 3 Bug #7778 - Model subclasses could not be deleted if a nullable foreign key relates to a model that relates back. >>> num_celebs = Celebrity.objects.count() >>> tvc = TvChef.objects.create(name="Huey") >>> Celebrity.objects.count() == num_celebs + 1 True >>> f1 = Fan.objects.create(fan_of=tvc) >>> f2 = Fan.objects.create(fan_of=tvc) >>> tvc.delete() # The parent object should have been deleted as well. >>> Celebrity.objects.count() == num_celebs True """} # In Python 2.3, exceptions raised in __len__ are swallowed (Python issue Loading