Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

newforms-admin: Fixed #7771 -- Improved the validation check on the o…

…rdering field. Now takes '?' and 'field1__field2' syntax into consideration. Thanks Michael Jung for catching this.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7931 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5317864e5fda896e777cfd001ec40a3c924b853a 1 parent 55744e9
@brosner brosner authored
View
6 django/contrib/admin/validation.py
@@ -79,8 +79,14 @@ def _check_attr_existsw(label, field):
"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
View
9 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)
@@ -611,6 +612,14 @@ class and an AdminSite instance, so let's just go ahead and do that manually
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)
Please sign in to comment.
Something went wrong with that request. Please try again.