Opened 9 years ago

Closed 7 years ago

#633 closed defect (invalid)

Model _post_load method (or similiar for a field?)

Reported by: wojtek@… Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


It would be nice to be able to do some operations right after an object is loaded from the DB. One example would be having some field which has to be pickled/unpickled when storing it in the DB.

This could be implemented either by adding a model _post_load method or by adding such a method to a field.

Any other workarounds which would work with current Django version that I'm missing?

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

This can be done by writing your own __init__ method on the model and just remember to call models.Model.__init__(....) first in your own function. Once the __init__ from the !Model class returns, the database fields will have been loaded and populated.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.