Задать вопрос

Тел: +7 965 3737 888

436

Просмотров

1

Ответов

pre_save hook for checking state changes to models

Trying to build a state-machine that stores state in the model or in settings.py rather then in the database, I wrote this small generic pre_save hook that lets me leave all the data in the Model.

Вопрос полезен? Да0/Нет0
file_5117.py(3.8Кб)
None

Ответы (1):

Ответfarmking:08.02.2012
Ответ полезен? Да0/Нет0

even simpler with tuples instead of dictionaries

states = ((from_state, to_state),)

for from_state, to_state in sender.VALID_STATE_CHANGES: if from_state == old.state and to_state == instance.state: return True