This code can run before django 1.7
But "related_name" got an error after django 1.8
{{{
使用者表.來源: (fields.E306) The name '使用者' is invalid related_name for
field 使用者表.來源
}}}
{{{
class 來源表(models.Model):
名 = models.CharField(max_length=100)
class 使用者表(models.Model):
來源 = models.OneToOneField(來源表, related_name='使用者',
primary_key=True, null=False)
}}}
Tim Graham said "It looks like the check added in ticket #22064 may be too
strict (only allowing alphanumeric characters in related_name)."
--
Ticket URL: <https://code.djangoproject.com/ticket/25016>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I think using
{{{
re.match('^[^\W\d]\w*$', related_name)
}}}
instead of
{{{
re.match('^[a-zA-Z_][a-zA-Z0-9_]*$', related_name)
}}}
in `django/db/models/fields/related.py`
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:1>
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
I think we should default to the old behavior on Py2:
`re.match('^[^\W\d]\w*$', related_name, re.unicode if six.PY3 else 0)`
While we're at it we should also replace the trailing `$` by a `\Z` to
prevent `'related_name\n'` from being accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:2>
Comment (by sih4sing5hong5):
I add some tests and do these in
https://github.com/django/django/pull/4911
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:3>
Comment (by bmispelon):
In python 3, we should probably use `str.isidentifier` [1] instead of
coding an ad-hoc regex.
[1]
https://docs.python.org/3/library/stdtypes.html?highlight=str.isidentifier#str.isidentifier
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:4>
Comment (by sih4sing5hong5):
How to write Unicode test like '試驗' string in python2 ?
`related_name` does not support unicode string in python2
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:5>
Comment (by zauddelig):
I added some notes on how make the tests work on github.
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:6>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* severity: Normal => Release blocker
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:7>
Comment (by sih4sing5hong5):
Thank for your suggestions. I updated the PR in github..
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"d3e12c901777697b7bf08b25e2dd46f0b951db8c" d3e12c9]:
{{{
#!CommitTicketReference repository=""
revision="d3e12c901777697b7bf08b25e2dd46f0b951db8c"
Fixed #25016 -- Reallowed non-ASCII values for ForeignKey.related_name on
Python 3.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a97e50c5e6afe0ce2a8fb2ca27c88e57611b0053" a97e50c5]:
{{{
#!CommitTicketReference repository=""
revision="a97e50c5e6afe0ce2a8fb2ca27c88e57611b0053"
[1.8.x] Fixed #25016 -- Reallowed non-ASCII values for
ForeignKey.related_name on Python 3.
Backport of d3e12c901777697b7bf08b25e2dd46f0b951db8c from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25016#comment:10>