Skip to content

Commit

Permalink
Fixed 14513 -- check fields with underscores for validity when orderi…
Browse files Browse the repository at this point in the history
…ng. Bonus points to Klaas van Schelven.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14315 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
SmileyChris committed Oct 21, 2010
1 parent 085e4c9 commit 051bf1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/core/management/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def get_validation_errors(outfile, app=None):
continue
# Skip ordering in the format field1__field2 (FIXME: checking
# this format would be nice, but it's a little fiddly).
if '_' in field_name:
if '__' in field_name:
continue
try:
opts.get_field(field_name, many_to_many=False)
Expand Down
4 changes: 4 additions & 0 deletions tests/modeltests/invalid_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class UniqueFKTarget2(models.Model):
""" Model to test for unique FK target in previously seen model: expect no error """
tgt = models.ForeignKey(FKTarget, to_field='good')

class NonExistingOrderingWithSingleUnderscore(models.Model):
class Meta:
ordering = ("does_not_exist",)

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

0 comments on commit 051bf1c

Please sign in to comment.