Author: brosner
Date: 2008-07-15 20:02:57 -0500 (Tue, 15 Jul 2008)
New Revision: 7931

Modified:
   django/branches/newforms-admin/django/contrib/admin/validation.py
   django/branches/newforms-admin/tests/regressiontests/modeladmin/models.py
Log:
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.

Modified: django/branches/newforms-admin/django/contrib/admin/validation.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/validation.py   
2008-07-15 22:41:17 UTC (rev 7930)
+++ django/branches/newforms-admin/django/contrib/admin/validation.py   
2008-07-16 01:02:57 UTC (rev 7931)
@@ -79,8 +79,14 @@
                         "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

Modified: 
django/branches/newforms-admin/tests/regressiontests/modeladmin/models.py
===================================================================
--- django/branches/newforms-admin/tests/regressiontests/modeladmin/models.py   
2008-07-15 22:41:17 UTC (rev 7930)
+++ django/branches/newforms-admin/tests/regressiontests/modeladmin/models.py   
2008-07-16 01:02:57 UTC (rev 7931)
@@ -30,6 +30,7 @@
     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 @@
 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)
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to