Skip to main content

A package to use transitions with a Django model.

Project description

django-model-fsm

A package to use transitions with a Django model.

Usage

from django.db import models

from django_model_fsm.dataclasses import StateData, TriggerData, WorkflowData
from django_model_fsm.models import TransitionsMixin

# States
# fmt: off
S_CREATED = StateData(
    id="created",
    label="Created",
)
S_PUBLISHED = StateData(
    id="published",
    label="Published",
)
S_ARCHIVED = StateData(
    id="archived",
    label="Archived",
)
# fmt: on

# Triggers
# fmt: off
T_PUBLISHED_CHALLENGE_MODEL = TriggerData(
    id="published_challenge_model",
    label="Publish",
    order=150,
    need_confirmation=False,
)
T_UNPUBLISHED_CHALLENGE_MODEL = TriggerData(
    id="unpublished_challenge_model",
    label="Unpublish",
    order=175,
    need_confirmation=True,
)
T_ARCHIVE_CHALLENGE_MODEL = TriggerData(
    id="archive_challenge_model",
    label="Archive",
    order=350,
    need_confirmation=True,
)
# fmt: on

challenge_model_workflow = WorkflowData(
    initial_state=S_CREATED,
    transitions_data=[
        # fmt: off
        {"trigger": T_PUBLISHED_CHALLENGE_MODEL, "source": S_CREATED, "dest": S_PUBLISHED},
        {"trigger": T_UNPUBLISHED_CHALLENGE_MODEL, "source": S_PUBLISHED, "dest": S_CREATED},
        {"trigger": T_ARCHIVE_CHALLENGE_MODEL, "source": S_PUBLISHED, "dest": S_ARCHIVED},
        # fmt: on
    ],
)


class MyModel(models.Model, TransitionsMixin):
    workflow_data = challenge_model_workflow
    workflow_callbacks = []

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_model_fsm-0.1.8.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

django_model_fsm-0.1.8-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file django_model_fsm-0.1.8.tar.gz.

File metadata

  • Download URL: django_model_fsm-0.1.8.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.13 Linux/6.1.0-17-amd64

File hashes

Hashes for django_model_fsm-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7e3aca9ab64e1edafa67eb99c42a73f728ad16f3daf1e7ecdd4d9b6d3647e2f3
MD5 3bcac683724bac974bc302b8021b8bd5
BLAKE2b-256 d71c3c9b3f584502ffcd4e243513bb1d967c487636e67b13e887bd81e883dcbe

See more details on using hashes here.

File details

Details for the file django_model_fsm-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: django_model_fsm-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.13 Linux/6.1.0-17-amd64

File hashes

Hashes for django_model_fsm-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 45fb6e7788933bb2039a0f312446e7af321172ecc47a2d88257d1d7a6f6ebd0b
MD5 9181c3f790f38356769d29df72c59606
BLAKE2b-256 ddb1de0ea041e6402916a918fdfa7760ef194548da506f5999eb9a128a033358

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page