mirror of https://github.com/django/django.git
Fixed #25560 -- Made empty string related_name invalid.
Thanks to Ali Lotfi for the initial report and patch and Tim Graham for the review.
This commit is contained in:
parent
4dcc2a1955
commit
c1b6a8a98b
|
@ -122,7 +122,7 @@ class RelatedField(Field):
|
|||
import re
|
||||
import keyword
|
||||
related_name = self.remote_field.related_name
|
||||
if not related_name:
|
||||
if related_name is None:
|
||||
return []
|
||||
is_valid_id = True
|
||||
if keyword.iskeyword(related_name):
|
||||
|
|
|
@ -154,7 +154,7 @@ class ForeignObjectRel(object):
|
|||
|
||||
def is_hidden(self):
|
||||
"Should the related object be hidden?"
|
||||
return self.related_name is not None and self.related_name[-1] == '+'
|
||||
return bool(self.related_name) and self.related_name[-1] == '+'
|
||||
|
||||
def get_joining_columns(self):
|
||||
return self.field.get_reverse_joining_columns()
|
||||
|
|
|
@ -662,6 +662,7 @@ class RelativeFieldTests(IsolatedModelsTestCase):
|
|||
'ends_with_whitespace_%s' % whitespace,
|
||||
'with', # a Python keyword
|
||||
'related_name\n',
|
||||
'',
|
||||
]
|
||||
# Python 2 crashes on non-ASCII strings.
|
||||
if six.PY3:
|
||||
|
|
Loading…
Reference in New Issue