diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index ef3de8f139f..67bf3b88dc7 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -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): diff --git a/django/db/models/fields/reverse_related.py b/django/db/models/fields/reverse_related.py index 015fa02165c..304e688d5aa 100644 --- a/django/db/models/fields/reverse_related.py +++ b/django/db/models/fields/reverse_related.py @@ -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() diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index 3ba95fdbe41..bfdd2b7d7af 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -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: