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:
parent
55744e997f
commit
5317864e5f
@ -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
|
||||
|
@ -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)
|
||||
@ -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.
|
||||
|
||||
>>> class ValidationTestModelAdmin(ModelAdmin):
|
||||
... ordering = ('?',)
|
||||
>>> validate(ValidationTestModelAdmin, ValidationTestModel)
|
||||
|
||||
>>> class ValidationTestModelAdmin(ModelAdmin):
|
||||
... ordering = ('band__name',)
|
||||
>>> validate(ValidationTestModelAdmin, ValidationTestModel)
|
||||
|
||||
>>> class ValidationTestModelAdmin(ModelAdmin):
|
||||
... ordering = ('name',)
|
||||
>>> validate(ValidationTestModelAdmin, ValidationTestModel)
|
||||
|
Loading…
x
Reference in New Issue
Block a user