You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# type: ignorefromdjango.dbimportmodelsfromdjango_fsmimportFSMIntegerFieldfromdjango_fsmimporttransitionfromdjango_fsm_log.modelsimportStateLogfromdjango.contrib.authimportUserfromdjango_fsm_log.decoratorsimportfsm_log_descriptionclassEntityStateLog(StateLog):
@propertydefstate_label(self):
returnself.get_state_display()
@propertydefsource_state_label(self):
returnself.get_source_state_display()
classMeta:
proxy=TrueclassEntity(models.Model):
""" Some description about what this entity is and why we define a model for it """classState(models.IntegerChoices):
""" Ennumeration type that defines the various states that an entity can goes through """FIRST_STATE=1, "First state"SECOND_STATE=2, "Second state"THIRD_STATE=3, "Third state"state=FSMIntegerField(default=State.FIRST_STATE, choices=State.choices)
description=models.TextField()
created_at=models.DateTimeField(auto_now_add=True)
@fsm_log_description@transition(state, source=[State.FIRST_STATE], target=State.SECOND_STATE)defdo_something(self, description=None):
...
defcan_do_other_thing(self, user):
returnuser.role==User.Role.SOME_ROLE@fsm_log_description@transition(state,source=[State.SECOND_STATE],target=State.THIRD_STATE,permission=can_do_other_thing, )defdo_other_thing(self, description=None):
...
@propertydefstate_logs(self):
returnEntityStateLog.objects.for_(self)
@propertydefstate_label(self):
returnself.get_state_display()
def__str__(self) ->str:
return"%s"% (self.description)