2 main API calls, get_fields and get_field.
>>> get_fields(types, opts, **kwargs)
(
(field_name, field_instance),
(field_name, field_instance),
(field_name, field_instance),
)
>>> get_field(field_name, with_details=False)
field_instance
>>> get_field(field_name, with_details=True)
field_instance, model, is_direct, is_m2m
Is referred to fields that actually contain information defined explicitly by the user. Example of this is DateField, CharField, BooleanField but this can also be a ForeignKey.
NOTE: do we want to have ForeignKey as part of DATA fields, or make it a separate type? My reasoning is to keep it as a data type until we realize there is a need of pulling it out.
By default it recursively searches through all the parent list and takes into consideration also non-concrete fields. This can be changed by using the options LOCAL_ONLY and CONCRETE
Is referred to ManyToManyField.
By default it recursively searches through all the parent list and excludes hidden fields. This can be changed by using the options INCLUDE_HIDDEN and LOCAL_ONLY
Is referred to related objects and m2m fields.
By default it searches recursively through all related and m2m objects excluding hidden and proxy objects. The options ONLY_* are used to keep only a subset, the options INCLUDE_* are only used if OBJECTS are included and will not have any effect if ONLY_M2M. LOCAL_ONLY can be used on any of these options.
Only get fields where column is not None
Only get fields on current model, do not recursively get fields of a type
INCLUDE_HIDDEN
Only possible on M2M fields (related and non): a hidden field is found through
is_hidden() == True
Proxy fields are found on a data field through:
field.model._meta == self
Proxy fields are found on a m2m field through:
field.rel.to._meta == self
Limits related fields only to M2M
Limits related fields only to objects
DATA | M2M | RELATED | |
---|---|---|---|
CONCRETE | YES | YES | NO |
LOCAL_ONLY | YES | YES | YES |
INCLUDE_HIDDEN | NO | YES | YES |
INCLUDE_PROXY | NO | NO | YES |
ONLY_M2M | NO | NO | YES |
ONLY_OBJECTS | NO | NO | YES |
This API is always incrementing the query by each flag. It never decreases of excludes fields based on bits