1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

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
This commit is contained in:
Brian Rosner 2008-07-16 01:02:57 +00:00
parent 55744e997f
commit 5317864e5f
2 changed files with 15 additions and 0 deletions

View File

@ -79,8 +79,14 @@ def validate(cls, model):
"ordering marker `?`, but contains other fields as " "ordering marker `?`, but contains other fields as "
"well. Please either remove `?` or the other fields." "well. Please either remove `?` or the other fields."
% cls.__name__) % cls.__name__)
if field == '?':
continue
if field.startswith('-'): if field.startswith('-'):
field = field[1:] 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) _check_field_existsw('ordering[%d]' % idx, field)
# list_select_related = False # list_select_related = False

View File

@ -30,6 +30,7 @@ class ValidationTestModel(models.Model):
state = models.CharField(max_length=2, choices=(("CO", "Colorado"), ("WA", "Washington"))) state = models.CharField(max_length=2, choices=(("CO", "Colorado"), ("WA", "Washington")))
is_active = models.BooleanField() is_active = models.BooleanField()
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
band = models.ForeignKey(Band)
class ValidationTestInlineModel(models.Model): class ValidationTestInlineModel(models.Model):
parent = models.ForeignKey(ValidationTestModel) 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. 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): >>> class ValidationTestModelAdmin(ModelAdmin):
... ordering = ('name',) ... ordering = ('name',)
>>> validate(ValidationTestModelAdmin, ValidationTestModel) >>> validate(ValidationTestModelAdmin, ValidationTestModel)