Skip to content
/ django Public

Commit 051bf1c

Browse files
committed
Fixed 14513 -- check fields with underscores for validity when ordering. Bonus points to Klaas van Schelven.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14315 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 085e4c9 commit 051bf1c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

django/core/management/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def get_validation_errors(outfile, app=None):
257257
continue
258258
# Skip ordering in the format field1__field2 (FIXME: checking
259259
# this format would be nice, but it's a little fiddly).
260-
if '_' in field_name:
260+
if '__' in field_name:
261261
continue
262262
try:
263263
opts.get_field(field_name, many_to_many=False)

tests/modeltests/invalid_models/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ class UniqueFKTarget2(models.Model):
206206
""" Model to test for unique FK target in previously seen model: expect no error """
207207
tgt = models.ForeignKey(FKTarget, to_field='good')
208208

209+
class NonExistingOrderingWithSingleUnderscore(models.Model):
210+
class Meta:
211+
ordering = ("does_not_exist",)
209212

210213
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
211214
invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
@@ -311,4 +314,5 @@ class UniqueFKTarget2(models.Model):
311314
invalid_models.uniquem2m: ManyToManyFields cannot be unique. Remove the unique argument on 'unique_people'.
312315
invalid_models.nonuniquefktarget1: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
313316
invalid_models.nonuniquefktarget2: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
317+
invalid_models.nonexistingorderingwithsingleunderscore: "ordering" refers to "does_not_exist", a field that doesn't exist.
314318
"""

0 commit comments

Comments
 (0)