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.2.7.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_model_fsm-0.2.7-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_model_fsm-0.2.7.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for django_model_fsm-0.2.7.tar.gz
Algorithm Hash digest
SHA256 000be30456e83b8ceed9faa866ceec96078c433ae880932cd9768bfb83772a54
MD5 bdfeb294809d08584dbb353a71a358dc
BLAKE2b-256 24f8e4fd19232caddcbc786577c67abd803c15a9ff5b1ee4cf94439322e86dba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_model_fsm-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4dff32d8fa50a204aeb87aa16c591aece6cf5fe3d3b184ba311b6ec6f221915f
MD5 def8a059299c4038dd8a2393654d577b
BLAKE2b-256 ebd28e38fa681a35177926c5aba150ca7e0e4aaf2225a1bf26685ad077465ffa

See more details on using hashes here.

Supported by

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