Internal helper function to return fields of the model. * If forward=True, then fields defined on this model are returned. * If reverse=True, then relations pointing to this model are returned. * If include_hidden=True, then fields with is_hidden=True are returned.
(
self,
forward=True,
reverse=True,
include_parents=True,
include_hidden=False,
topmost_call=True,
)
| 879 | ) |
| 880 | |
| 881 | def _get_fields( |
| 882 | self, |
| 883 | forward=True, |
| 884 | reverse=True, |
| 885 | include_parents=True, |
| 886 | include_hidden=False, |
| 887 | topmost_call=True, |
| 888 | ): |
| 889 | """ |
| 890 | Internal helper function to return fields of the model. |
| 891 | * If forward=True, then fields defined on this model are returned. |
| 892 | * If reverse=True, then relations pointing to this model are returned. |
| 893 | * If include_hidden=True, then fields with is_hidden=True are returned. |
| 894 | * The include_parents argument toggles if fields from parent models |
| 895 | should be included. It has three values: True, False, and |
| 896 | PROXY_PARENTS. When set to PROXY_PARENTS, the call will return all |
| 897 | fields defined for the current model or any of its parents in the |
| 898 | parent chain to the model's concrete model. |
| 899 | """ |
| 900 | if include_parents not in (True, False, PROXY_PARENTS): |
| 901 | raise TypeError( |
| 902 | "Invalid argument for include_parents: %s" % (include_parents,) |
| 903 | ) |
| 904 | # This helper function is used to allow recursion in ``get_fields()`` |
| 905 | # implementation and to provide a fast way for Django's internals to |
| 906 | # access specific subsets of fields. |
| 907 | |
| 908 | # Creates a cache key composed of all arguments |
| 909 | cache_key = (forward, reverse, include_parents, include_hidden, topmost_call) |
| 910 | |
| 911 | try: |
| 912 | # In order to avoid list manipulation. Always return a shallow copy |
| 913 | # of the results. |
| 914 | return self._get_fields_cache[cache_key] |
| 915 | except KeyError: |
| 916 | pass |
| 917 | |
| 918 | fields = [] |
| 919 | # Recursively call _get_fields() on each parent, with the same |
| 920 | # options provided in this call. |
| 921 | if include_parents is not False: |
| 922 | # In diamond inheritance it is possible that we see the same model |
| 923 | # from two different routes. In that case, avoid adding fields from |
| 924 | # the same parent again. |
| 925 | parent_fields = set() |
| 926 | for parent in self.parents: |
| 927 | if ( |
| 928 | parent._meta.concrete_model != self.concrete_model |
| 929 | and include_parents == PROXY_PARENTS |
| 930 | ): |
| 931 | continue |
| 932 | for obj in parent._meta._get_fields( |
| 933 | forward=forward, |
| 934 | reverse=reverse, |
| 935 | include_parents=include_parents, |
| 936 | include_hidden=include_hidden, |
| 937 | topmost_call=False, |
| 938 | ): |
no test coverage detected