1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

Fixed #21961 -- Added support for database-level delete options for ForeignKey.

Thanks Simon Charette for pair programming.

Co-authored-by: Nick Stefan <NickStefan12@gmail.com>
Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com>
Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
Mariusz Felisiak
2025-10-18 15:03:50 +02:00
committed by GitHub
parent b1e0262c9f
commit 0c487aa3a7
33 changed files with 838 additions and 67 deletions

View File

@@ -26,7 +26,17 @@ from django.test.utils import isolate_apps
from django.utils.formats import localize
from django.utils.safestring import mark_safe
from .models import Article, Car, Count, Event, EventGuide, Location, Site, Vehicle
from .models import (
Article,
Car,
Cascade,
DBCascade,
Event,
EventGuide,
Location,
Site,
Vehicle,
)
class NestedObjectsTests(TestCase):
@@ -34,10 +44,12 @@ class NestedObjectsTests(TestCase):
Tests for ``NestedObject`` utility collection.
"""
cascade_model = Cascade
@classmethod
def setUpTestData(cls):
cls.n = NestedObjects(using=DEFAULT_DB_ALIAS)
cls.objs = [Count.objects.create(num=i) for i in range(5)]
cls.objs = [cls.cascade_model.objects.create(num=i) for i in range(5)]
def _check(self, target):
self.assertEqual(self.n.nested(lambda obj: obj.num), target)
@@ -103,6 +115,15 @@ class NestedObjectsTests(TestCase):
n.collect([Vehicle.objects.first()])
class DBNestedObjectsTests(NestedObjectsTests):
"""
Exercise NestedObjectsTests but with a model that makes use of DB_CASCADE
instead of CASCADE to ensure proper collection of objects takes place.
"""
cascade_model = DBCascade
class UtilsTests(SimpleTestCase):
empty_value = "-empty-"