summaryrefslogtreecommitdiff
path: root/tests/admin_registration
diff options
context:
space:
mode:
authorBendeguz Csirmaz <csirmazbendeguz@gmail.com>2024-04-07 10:32:16 +0800
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-29 11:23:04 +0100
commit978aae4334fa71ba78a3e94408f0f3aebde8d07c (patch)
treedd1cc322769441a3dd28b952ce52e07c3f72f90a /tests/admin_registration
parent86661f2449fb0903f72b3522c68e146934013377 (diff)
Fixed #373 -- Added CompositePrimaryKey.
Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Lily Foote <code@lilyf.org>
Diffstat (limited to 'tests/admin_registration')
-rw-r--r--tests/admin_registration/models.py6
-rw-r--r--tests/admin_registration/tests.py10
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/admin_registration/models.py b/tests/admin_registration/models.py
index 0ae9251133..2231c236de 100644
--- a/tests/admin_registration/models.py
+++ b/tests/admin_registration/models.py
@@ -20,3 +20,9 @@ class Location(models.Model):
class Place(Location):
name = models.CharField(max_length=200)
+
+
+class Guest(models.Model):
+ pk = models.CompositePrimaryKey("traveler", "place")
+ traveler = models.ForeignKey(Traveler, on_delete=models.CASCADE)
+ place = models.ForeignKey(Place, on_delete=models.CASCADE)
diff --git a/tests/admin_registration/tests.py b/tests/admin_registration/tests.py
index 3b0e656f5f..0a881caf65 100644
--- a/tests/admin_registration/tests.py
+++ b/tests/admin_registration/tests.py
@@ -5,7 +5,7 @@ from django.contrib.admin.sites import site
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase
-from .models import Location, Person, Place, Traveler
+from .models import Guest, Location, Person, Place, Traveler
class NameAdmin(admin.ModelAdmin):
@@ -92,6 +92,14 @@ class TestRegistration(SimpleTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
self.site.register(Location)
+ def test_composite_pk_model(self):
+ msg = (
+ "The model Guest has a composite primary key, so it cannot be registered "
+ "with admin."
+ )
+ with self.assertRaisesMessage(ImproperlyConfigured, msg):
+ self.site.register(Guest)
+
def test_is_registered_model(self):
"Checks for registered models should return true."
self.site.register(Person)