Changes between Version 22 and Version 23 of new_meta_api


Ignore:
Timestamp:
Sep 11, 2014, 8:48:14 AM (10 years ago)
Author:
pirosb3
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • new_meta_api

    v22 v23  
    321321Give me as much feedback as you can, you can also ping me on IRC or mail (pirosb3 at gmail). A simple way to give feedback is also to have a look at the Pull Request and comment if you see something that can be improved.
    322322
    323 ==== Next Steps
    324 - Feedback
    325 - Code cleanup and code documentation
    326 - Django manual documentation
    327 - Decide deprecaction strategy
    328 - More benchmarking
    329 - Merge
     323
     324== Further API improvements
     325
     326After a number of iterations, and many discussions on the Mailing List ( https://groups.google.com/forum/#!topic/django-developers/XfMUjK59Sls) we have come up with the new, simplified, API.
     327
     328=== Model._meta API functions
     329
     330{{{
     331    def get_fields(self, forward=True, reverse=False)
     332}}}
     333
     334We have made a distinction between fields that are on the model (forward) and fields that point to the model (reverse). Compared to the previous API we are not making a distinction on if a field is a M2M, Foreign Key, or normal "data" field. This allows greater flexibility in the future and only makes one clear separation of field types. API consumers will be able to do further filtering using the field_flags (see below)
     335
     336 {{{
     337    def get_field(self, field_name)
     338}}}
     339
     340We have dropped the include_relations flag because it is no longer required. The API is still 100% backwards compatible. A field can be a reverse or a forward field and can be accessed using 1 or more names (ex. {"user", "user_id"}).
     341
     342
     343=== Model._meta API accessors
     344
     345===== _meta.fields
     346Returns all forward fields that may have relations and store only 1 single value.
     347
     348===== _meta.many_to_many
     349Returns all forward fields that may have relations and store multiple values.
     350
     351===== _meta.concrete_fields
     352Returns all forward concrete fields that may have relations and store only 1 single value.
     353
     354===== _meta.local_concrete_fields
     355Returns all forward concrete fields, defined on the current model, that may have relations and store only 1 single value.
     356
     357===== _meta.related_objects
     358Returns all the reverse objects pointing to the current model.
     359
     360
     361
     362This API has remained the same, but the newer implementation is more efficient.
     363
     364
     365
     366==== Use cached_properties when possible
     367Function calls are expensive in Python, All sensible attributes with no arguments have been transformed into cached_properties.
     368A 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,
     369local_concrete_fields, many_to_many, field_names
     370
     371
     372
Back to Top