Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add django support #13

Open
lamenezes opened this issue Jun 23, 2019 · 0 comments
Open

add django support #13

lamenezes opened this issue Jun 23, 2019 · 0 comments

Comments

@lamenezes
Copy link
Owner

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 found

instead 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant