360 | | |
361 | | |
362 | | This API has remained the same, but the newer implementation is more efficient. |
363 | | |
364 | | |
365 | | |
366 | | ==== Use cached_properties when possible |
367 | | Function calls are expensive in Python, All sensible attributes with no arguments have been transformed into cached_properties. |
368 | | A cached property is a read-only property that is calculated on demand and automatically cached. If the value has already been calculated, the cached value is returned. Cached properties avoid a new stack and are used for fast-access to fields, concrete_fields, |
369 | | local_concrete_fields, many_to_many, field_names |
370 | | |
371 | | |
372 | | |
| 360 | ===== _meta.field_names |
| 361 | This API has remains the same, but the newer implementation is more efficient. |
| 362 | |
| 363 | === Field flags |
| 364 | Each field and/or object defines a set of flags that are used by the developer to manually narrow down the search or iteration of the above API calls. By defining field flags, we give the possibility for developers to create custom-made field instances that can behave correctly in an admin interface or in auto-generated model forms. |
| 365 | |
| 366 | ===== field.concrete |
| 367 | A concrete field has a database column associated to it's field instance. |
| 368 | |
| 369 | ===== field.editable |
| 370 | An editable field is a field that's data can be manipulated (an Autofield for example should not be manipulated and responds False to an "editable" query). |
| 371 | |
| 372 | ===== field.has_many_values |
| 373 | A field that can contain 1 or more values. This does not need to necessary be a ManyToMany field, but can also be a future ArrayField. |
| 374 | |
| 375 | ===== field.has_relation |
| 376 | A field has a relation when it depends on 1 or more models, and therefore might generate reverse relations on the pointed model. |
| 377 | |
| 378 | ===== object.is_related_object and field.is_related_object |
| 379 | A very simple way to query if an object returned from get_field() or get_fields() is a reverse object or a forward object. |