MCPcopy
hub / github.com/django/django / _check_local_fields

Method _check_local_fields

django/db/models/base.py:2197–2273  ·  view source on GitHub ↗
(cls, fields, option)

Source from the content-addressed store, hash-verified

2195
2196 @classmethod
2197 def _check_local_fields(cls, fields, option):
2198 from django.db import models
2199
2200 # In order to avoid hitting the relation tree prematurely, we use our
2201 # own fields_map instead of using get_field()
2202 forward_fields_map = {}
2203 for field in cls._meta._get_fields(reverse=False):
2204 forward_fields_map[field.name] = field
2205 if hasattr(field, "attname"):
2206 forward_fields_map[field.attname] = field
2207
2208 errors = []
2209 for field_name in fields:
2210 try:
2211 field = forward_fields_map[field_name]
2212 except KeyError:
2213 errors.append(
2214 checks.Error(
2215 "'%s' refers to the nonexistent field '%s'."
2216 % (
2217 option,
2218 field_name,
2219 ),
2220 obj=cls,
2221 id="models.E012",
2222 )
2223 )
2224 else:
2225 if isinstance(field.remote_field, models.ManyToManyRel):
2226 errors.append(
2227 checks.Error(
2228 "'%s' refers to a ManyToManyField '%s', but "
2229 "ManyToManyFields are not permitted in '%s'."
2230 % (
2231 option,
2232 field_name,
2233 option,
2234 ),
2235 obj=cls,
2236 id="models.E013",
2237 )
2238 )
2239 elif isinstance(field, models.CompositePrimaryKey):
2240 errors.append(
2241 checks.Error(
2242 f"{option!r} refers to a CompositePrimaryKey "
2243 f"{field_name!r}, but CompositePrimaryKeys are not "
2244 f"permitted in {option!r}.",
2245 obj=cls,
2246 id="models.E048",
2247 )
2248 )
2249 elif (
2250 isinstance(field.remote_field, ForeignObjectRel)
2251 and field not in cls._meta.local_concrete_fields
2252 and len(field.from_fields) > 1
2253 ):
2254 errors.append(

Callers 4

checkMethod · 0.80
_check_referencesMethod · 0.80
checkMethod · 0.80

Calls 2

_get_fieldsMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected