diff options
| author | Brian Rosner <brosner@gmail.com> | 2008-07-16 01:02:57 +0000 |
|---|---|---|
| committer | Brian Rosner <brosner@gmail.com> | 2008-07-16 01:02:57 +0000 |
| commit | 5317864e5fda896e777cfd001ec40a3c924b853a (patch) | |
| tree | 42d4e94b3364046a487a3c7e8f86f8655af01671 | |
| parent | 55744e997f92f24608910eecf60509603ec87fec (diff) | |
newforms-admin: Fixed #7771 -- Improved the validation check on the ordering 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
| -rw-r--r-- | django/contrib/admin/validation.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/modeladmin/models.py | 9 |
2 files changed, 15 insertions, 0 deletions
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) @@ -611,6 +612,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) |
