summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--django/contrib/admin/checks.py2
-rw-r--r--docs/ref/checks.txt4
-rw-r--r--docs/ref/contrib/admin/index.txt2
-rw-r--r--tests/modeladmin/models.py1
-rw-r--r--tests/modeladmin/tests.py15
6 files changed, 19 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
index 2f54055a28..efd6071c6c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -299,6 +299,7 @@ answer newbie questions, and generally made Django that much better:
Hawkeye
Helen Sherwood-Taylor <helen@rrdlabs.co.uk>
Henrique Romano <onaiort@gmail.com>
+ Henry Dang <henrydangprg@gmail.com>
hipertracker@gmail.com
Hiroki Kiyohara <hirokiky@gmail.com>
Honza Král <honza.kral@gmail.com>
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 1d802d2fbe..91fa85f0f8 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -399,7 +399,7 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of '%s' refers to '%s', which must not be a DateTimeField, "
- "a ForeignKey, or a ManyToManyField." % (label, field_name),
+ "a ForeignKey, a OneToOneField, or a ManyToManyField." % (label, field_name),
obj=obj.__class__,
id='admin.E028',
)
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index 1f35c5bb0f..3b16921e52 100644
--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -343,8 +343,8 @@ with the admin site:
* **admin.E027**: The value of ``prepopulated_fields`` refers to
``<field name>``, which is not an attribute of ``<model>``.
* **admin.E028**: The value of ``prepopulated_fields`` refers to
- ``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``, or a
- ``ManyToManyField`` field.
+ ``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``,
+ a ``OneToOneField``, or a ``ManyToManyField`` field.
* **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
list or tuple.
* **admin.E030**: The value of ``prepopulated_fields`` refers to
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 59d756db99..e30076b487 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -1059,7 +1059,7 @@ subclass::
slug (e.g. substituting dashes for spaces).
``prepopulated_fields`` doesn't accept ``DateTimeField``, ``ForeignKey``,
- nor ``ManyToManyField`` fields.
+ ``OneToOneField``, and ``ManyToManyField`` fields.
.. attribute:: ModelAdmin.preserve_filters
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):