-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
it would be great if when working with django we could do something like:
from status_map.django import StatusField
class Task(Model):
status = StatusField(status_map={'todo': ['doing'], 'doing': ['todo', 'done'], 'done': []})
title = CharField(...)
>>> task = Task(title='implement django support on status-map') # defaults to the first status passed (todo)
>>> task.status = 'done'
>>> task.save()
status_map.exceptions.TransitionNotFoundError: transition from todo to done not foundinstead of something like:
from status_map import StatusMap
TASK_STATUS_MAP = StatusMap({'todo': ['doing'], 'doing': ['todo', 'done'], 'done': []})
class Task(Model):
status = ChoiceField(choices=TASK_STATUS_MAP._map.keys(), default='todo')
# not using validators because I'm pretty sure we can't acess the current status on the db
def save(self, *args, **kwargs):
task = Task.objects.get(pk=self.pk)
if task.status != self.status:
TASK_STATUS_MAP.validate_transition(task.status, self.status)
return super().save(*args, **kwargs)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels