1
0
mirror of https://github.com/django/django.git synced 2025-10-29 00:26:07 +00:00

[1.8.x] Fixed #25016 -- Reallowed non-ASCII values for ForeignKey.related_name on Python 3.

Backport of d3e12c9017 from master
This commit is contained in:
薛丞宏
2015-06-23 14:08:12 +08:00
committed by Tim Graham
parent ae93aeed2b
commit a97e50c5e6
4 changed files with 25 additions and 6 deletions

View File

@@ -122,10 +122,18 @@ class RelatedField(Field):
import re
import keyword
related_name = self.rel.related_name
is_valid_id = (related_name and re.match('^[a-zA-Z_][a-zA-Z0-9_]*$', related_name)
and not keyword.iskeyword(related_name))
if related_name and not (is_valid_id or related_name.endswith('+')):
if not related_name:
return []
is_valid_id = True
if keyword.iskeyword(related_name):
is_valid_id = False
if six.PY3:
if not related_name.isidentifier():
is_valid_id = False
else:
if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*\Z', related_name):
is_valid_id = False
if not (is_valid_id or related_name.endswith('+')):
return [
checks.Error(
"The name '%s' is invalid related_name for field %s.%s" %