Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Brian Rosner authored July 16, 2008
6  django/contrib/admin/validation.py
@@ -79,8 +79,14 @@ def _check_attr_existsw(label, field):
79 79
                         "ordering marker `?`, but contains other fields as "
80 80
                         "well. Please either remove `?` or the other fields."
81 81
                         % cls.__name__)
  82
+            if field == '?':
  83
+                continue
82 84
             if field.startswith('-'):
83 85
                 field = field[1:]
  86
+            # Skip ordering in the format field1__field2 (FIXME: checking
  87
+            # this format would be nice, but it's a little fiddly).
  88
+            if '__' in field:
  89
+                continue
84 90
             _check_field_existsw('ordering[%d]' % idx, field)
85 91
 
86 92
     # list_select_related = False
9  tests/regressiontests/modeladmin/models.py
@@ -30,6 +30,7 @@ class ValidationTestModel(models.Model):
30 30
     state = models.CharField(max_length=2, choices=(("CO", "Colorado"), ("WA", "Washington")))
31 31
     is_active = models.BooleanField()
32 32
     pub_date = models.DateTimeField()
  33
+    band = models.ForeignKey(Band)
33 34
 
34 35
 class ValidationTestInlineModel(models.Model):
35 36
     parent = models.ForeignKey(ValidationTestModel)
@@ -611,6 +612,14 @@ class and an AdminSite instance, so let's just go ahead and do that manually
611 612
 ImproperlyConfigured: `ValidationTestModelAdmin.ordering` has the random ordering marker `?`, but contains other fields as well. Please either remove `?` or the other fields.
612 613
 
613 614
 >>> class ValidationTestModelAdmin(ModelAdmin):
  615
+...     ordering = ('?',)
  616
+>>> validate(ValidationTestModelAdmin, ValidationTestModel)
  617
+
  618
+>>> class ValidationTestModelAdmin(ModelAdmin):
  619
+...     ordering = ('band__name',)
  620
+>>> validate(ValidationTestModelAdmin, ValidationTestModel)
  621
+
  622
+>>> class ValidationTestModelAdmin(ModelAdmin):
614 623
 ...     ordering = ('name',)
615 624
 >>> validate(ValidationTestModelAdmin, ValidationTestModel)
616 625
 

0 notes on commit 5317864

Please sign in to comment.
Something went wrong with that request. Please try again.