summaryrefslogtreecommitdiff
path: root/tests/modeladmin
diff options
context:
space:
mode:
authorHenry Dang <henrydangprg@gmail.com>2016-12-19 08:33:46 -0500
committerTim Graham <timograham@gmail.com>2016-12-19 08:33:46 -0500
commit6af23a4521fcf80aec7c5ee3988914423c7dfccd (patch)
tree5dc651c6a0675b0547eb175e8cd026d297f78859 /tests/modeladmin
parent3e43d24ad36d45cace57e6a7efd34638577ae744 (diff)
downloaddjango-6af23a4521fcf80aec7c5ee3988914423c7dfccd.tar.gz
Fixed #27377 -- Clarified that prepopulated_fields doesn't work with OneToOneField.
Diffstat (limited to 'tests/modeladmin')
-rw-r--r--tests/modeladmin/models.py1
-rw-r--r--tests/modeladmin/tests.py15
2 files changed, 14 insertions, 2 deletions
diff --git a/tests/modeladmin/models.py b/tests/modeladmin/models.py
index 2c2a910892..941032bf77 100644
--- a/tests/modeladmin/models.py
+++ b/tests/modeladmin/models.py
@@ -36,6 +36,7 @@ class ValidationTestModel(models.Model):
is_active = models.BooleanField(default=False)
pub_date = models.DateTimeField()
band = models.ForeignKey(Band, models.CASCADE)
+ best_friend = models.OneToOneField(User, models.CASCADE)
# This field is intentionally 2 characters long (#16080).
no = models.IntegerField(verbose_name="Number", blank=True, null=True)
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index ba75deff13..f8b4b5fae1 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -1006,8 +1006,8 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
- ("The value of 'prepopulated_fields' refers to 'users', which must not be "
- "a DateTimeField, a ForeignKey, or a ManyToManyField."),
+ "The value of 'prepopulated_fields' refers to 'users', which must not be "
+ "a DateTimeField, a ForeignKey, a OneToOneField, or a ManyToManyField.",
'admin.E028')
def test_valid_case(self):
@@ -1016,6 +1016,17 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel)
+ def test_one_to_one_field(self):
+ class ValidationTestModelAdmin(ModelAdmin):
+ prepopulated_fields = {'best_friend': ('name',)}
+
+ self.assertIsInvalid(
+ ValidationTestModelAdmin, ValidationTestModel,
+ "The value of 'prepopulated_fields' refers to 'best_friend', which must not be "
+ "a DateTimeField, a ForeignKey, a OneToOneField, or a ManyToManyField.",
+ 'admin.E028'
+ )
+
class ListDisplayTests(CheckTestCase):