diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 1173098668..fbf7de02ed 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -79,8 +79,14 @@ def validate(cls, model): "ordering marker `?`, but contains other fields as " "well. Please either remove `?` or the other fields." % cls.__name__) + if field == '?': + continue if field.startswith('-'): field = field[1:] + # Skip ordering in the format field1__field2 (FIXME: checking + # this format would be nice, but it's a little fiddly). + if '__' in field: + continue _check_field_existsw('ordering[%d]' % idx, field) # list_select_related = False diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py index f95fec80d0..39f8599a78 100644 --- a/tests/regressiontests/modeladmin/models.py +++ b/tests/regressiontests/modeladmin/models.py @@ -30,6 +30,7 @@ class ValidationTestModel(models.Model): state = models.CharField(max_length=2, choices=(("CO", "Colorado"), ("WA", "Washington"))) is_active = models.BooleanField() pub_date = models.DateTimeField() + band = models.ForeignKey(Band) class ValidationTestInlineModel(models.Model): parent = models.ForeignKey(ValidationTestModel) @@ -610,6 +611,14 @@ Traceback (most recent call last): ... ImproperlyConfigured: `ValidationTestModelAdmin.ordering` has the random ordering marker `?`, but contains other fields as well. Please either remove `?` or the other fields. +>>> class ValidationTestModelAdmin(ModelAdmin): +... ordering = ('?',) +>>> validate(ValidationTestModelAdmin, ValidationTestModel) + +>>> class ValidationTestModelAdmin(ModelAdmin): +... ordering = ('band__name',) +>>> validate(ValidationTestModelAdmin, ValidationTestModel) + >>> class ValidationTestModelAdmin(ModelAdmin): ... ordering = ('name',) >>> validate(ValidationTestModelAdmin, ValidationTestModel)