mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #27295 -- Added a system check to prohibit model names that start or end with an underscore or contain double underscores.
This commit is contained in:
committed by
Tim Graham
parent
41759c9082
commit
f62abfc03d
@@ -1265,7 +1265,11 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
errors.extend(cls._check_fields(**kwargs))
|
||||
errors.extend(cls._check_m2m_through_same_relationship())
|
||||
errors.extend(cls._check_long_column_names())
|
||||
clash_errors = cls._check_id_field() + cls._check_field_name_clashes()
|
||||
clash_errors = (
|
||||
cls._check_id_field() +
|
||||
cls._check_field_name_clashes() +
|
||||
cls._check_model_name_db_lookup_clashes()
|
||||
)
|
||||
errors.extend(clash_errors)
|
||||
# If there are field name clashes, hide consequent column name
|
||||
# clashes.
|
||||
@@ -1469,6 +1473,30 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
|
||||
return errors
|
||||
|
||||
@classmethod
|
||||
def _check_model_name_db_lookup_clashes(cls):
|
||||
errors = []
|
||||
model_name = cls.__name__
|
||||
if model_name.startswith('_') or model_name.endswith('_'):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The model name '%s' cannot start or end with an underscore "
|
||||
"as it collides with the query lookup syntax." % model_name,
|
||||
obj=cls,
|
||||
id='models.E023'
|
||||
)
|
||||
)
|
||||
elif LOOKUP_SEP in model_name:
|
||||
errors.append(
|
||||
checks.Error(
|
||||
"The model name '%s' cannot contain double underscores as "
|
||||
"it collides with the query lookup syntax." % model_name,
|
||||
obj=cls,
|
||||
id='models.E024'
|
||||
)
|
||||
)
|
||||
return errors
|
||||
|
||||
@classmethod
|
||||
def _check_index_together(cls):
|
||||
""" Check the value of "index_together" option. """
|
||||
|
||||
Reference in New Issue
Block a user