MCPcopy
hub / github.com/django/django / fields

Method fields

django/db/models/options.py:532–571  ·  view source on GitHub ↗

Return a list of all forward fields on the model and its parents, excluding ManyToManyFields. Private API intended only to be used by Django itself; get_fields() combined with filtering of field properties is the public API for obtaining this field list.

(self)

Source from the content-addressed store, hash-verified

530
531 @cached_property
532 def fields(self):
533 """
534 Return a list of all forward fields on the model and its parents,
535 excluding ManyToManyFields.
536
537 Private API intended only to be used by Django itself; get_fields()
538 combined with filtering of field properties is the public API for
539 obtaining this field list.
540 """
541
542 # For legacy reasons, the fields property should only contain forward
543 # fields that are not private or with a m2m cardinality. Therefore we
544 # pass these three filters as filters to the generator.
545 # The third filter is a longwinded way of checking f.related_model - we
546 # don't use that property directly because related_model is a cached
547 # property, and all the models may not have been loaded yet; we don't
548 # want to cache the string reference to the related_model.
549 def is_not_an_m2m_field(f):
550 return not (f.is_relation and f.many_to_many)
551
552 def is_not_a_generic_relation(f):
553 return not (f.is_relation and f.one_to_many)
554
555 def is_not_a_generic_foreign_key(f):
556 return not (
557 f.is_relation
558 and f.many_to_one
559 and not (hasattr(f.remote_field, "model") and f.remote_field.model)
560 )
561
562 return make_immutable_fields_list(
563 "fields",
564 (
565 f
566 for f in self._get_fields(reverse=False)
567 if is_not_an_m2m_field(f)
568 and is_not_a_generic_relation(f)
569 and is_not_a_generic_foreign_key(f)
570 ),
571 )
572
573 @cached_property
574 def concrete_fields(self):

Callers

nothing calls this directly

Calls 2

_get_fieldsMethod · 0.95

Tested by

no test coverage detected