Opened 5 years ago

Last modified 4 years ago

#31701 closed Cleanup/optimization

Extend DeferredAttribute & Remove unnecessary overriding of contrib_to_class () in FileField — at Initial Version

Reported by: Sultan Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The model fields use, by default, the descriptor DeferredAttribute to access and process (if necessary) the data associated with them. This type of data represents the actual data in db column. I prefer to call it a “field data”.

To access the field data in instance dict, Field.attname is used as a key.

In addition to the field data, some other model fields (for example, FK) also use a "client data" of the attribute, the processing of which is performed by a particular descriptor. Such a descriptor is usually assigned to a model using Field.name.

This enables us to process and present data in different ways: article.author returns a User object, and article.auther_id returns a User object pk.

This feature is not used in model.FileField. Then why use FileField.name instead of FileField.attname for FileDescriptor?

I think it would be better if FileDescriptor uses field.attname and continue working with the DeferredAttribute class.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top