Fixed #27377 -- Clarified that prepopulated_fields doesn't work with OneToOneField.
This commit is contained in:
parent
3e43d24ad3
commit
6af23a4521
1
AUTHORS
1
AUTHORS
|
@ -299,6 +299,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Hawkeye
|
Hawkeye
|
||||||
Helen Sherwood-Taylor <helen@rrdlabs.co.uk>
|
Helen Sherwood-Taylor <helen@rrdlabs.co.uk>
|
||||||
Henrique Romano <onaiort@gmail.com>
|
Henrique Romano <onaiort@gmail.com>
|
||||||
|
Henry Dang <henrydangprg@gmail.com>
|
||||||
hipertracker@gmail.com
|
hipertracker@gmail.com
|
||||||
Hiroki Kiyohara <hirokiky@gmail.com>
|
Hiroki Kiyohara <hirokiky@gmail.com>
|
||||||
Honza Král <honza.kral@gmail.com>
|
Honza Král <honza.kral@gmail.com>
|
||||||
|
|
|
@ -399,7 +399,7 @@ class BaseModelAdminChecks(object):
|
||||||
return [
|
return [
|
||||||
checks.Error(
|
checks.Error(
|
||||||
"The value of '%s' refers to '%s', which must not be a DateTimeField, "
|
"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__,
|
obj=obj.__class__,
|
||||||
id='admin.E028',
|
id='admin.E028',
|
||||||
)
|
)
|
||||||
|
|
|
@ -343,8 +343,8 @@ with the admin site:
|
||||||
* **admin.E027**: The value of ``prepopulated_fields`` refers to
|
* **admin.E027**: The value of ``prepopulated_fields`` refers to
|
||||||
``<field name>``, which is not an attribute of ``<model>``.
|
``<field name>``, which is not an attribute of ``<model>``.
|
||||||
* **admin.E028**: The value of ``prepopulated_fields`` refers to
|
* **admin.E028**: The value of ``prepopulated_fields`` refers to
|
||||||
``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``, or a
|
``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``,
|
||||||
``ManyToManyField`` field.
|
a ``OneToOneField``, or a ``ManyToManyField`` field.
|
||||||
* **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
|
* **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
|
||||||
list or tuple.
|
list or tuple.
|
||||||
* **admin.E030**: The value of ``prepopulated_fields`` refers to
|
* **admin.E030**: The value of ``prepopulated_fields`` refers to
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ subclass::
|
||||||
slug (e.g. substituting dashes for spaces).
|
slug (e.g. substituting dashes for spaces).
|
||||||
|
|
||||||
``prepopulated_fields`` doesn't accept ``DateTimeField``, ``ForeignKey``,
|
``prepopulated_fields`` doesn't accept ``DateTimeField``, ``ForeignKey``,
|
||||||
nor ``ManyToManyField`` fields.
|
``OneToOneField``, and ``ManyToManyField`` fields.
|
||||||
|
|
||||||
.. attribute:: ModelAdmin.preserve_filters
|
.. attribute:: ModelAdmin.preserve_filters
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ class ValidationTestModel(models.Model):
|
||||||
is_active = models.BooleanField(default=False)
|
is_active = models.BooleanField(default=False)
|
||||||
pub_date = models.DateTimeField()
|
pub_date = models.DateTimeField()
|
||||||
band = models.ForeignKey(Band, models.CASCADE)
|
band = models.ForeignKey(Band, models.CASCADE)
|
||||||
|
best_friend = models.OneToOneField(User, models.CASCADE)
|
||||||
# This field is intentionally 2 characters long (#16080).
|
# This field is intentionally 2 characters long (#16080).
|
||||||
no = models.IntegerField(verbose_name="Number", blank=True, null=True)
|
no = models.IntegerField(verbose_name="Number", blank=True, null=True)
|
||||||
|
|
||||||
|
|
|
@ -1006,8 +1006,8 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
|
||||||
|
|
||||||
self.assertIsInvalid(
|
self.assertIsInvalid(
|
||||||
ValidationTestModelAdmin, ValidationTestModel,
|
ValidationTestModelAdmin, ValidationTestModel,
|
||||||
("The value of 'prepopulated_fields' refers to 'users', which must not be "
|
"The value of 'prepopulated_fields' refers to 'users', which must not be "
|
||||||
"a DateTimeField, a ForeignKey, or a ManyToManyField."),
|
"a DateTimeField, a ForeignKey, a OneToOneField, or a ManyToManyField.",
|
||||||
'admin.E028')
|
'admin.E028')
|
||||||
|
|
||||||
def test_valid_case(self):
|
def test_valid_case(self):
|
||||||
|
@ -1016,6 +1016,17 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
|
||||||
|
|
||||||
self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel)
|
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):
|
class ListDisplayTests(CheckTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue