@@ -17,6 +17,9 @@ by enabling a cached backend. See [Advanced Usage](#advanced-usage)
1717## 4.0.0 (not released)
1818
1919- remove support for django 2.2 & 4.0
20+ - Bring your own PersistedTransition model:
21+ From this relase, django-fsm-log is deprecating StateLog and instead encourages you
22+ to define for your own application the concrete model that will persist the transition
2023
2124## 3.1.0 (2023-03-23)
2225
@@ -99,14 +102,29 @@ python manage.py migrate django_fsm_log
99102
100103## Usage
101104
105+ ### Define you own model
106+
107+ ``` python
108+ from django_fsm_log.models import PersistedTransitionMixin
109+
110+
111+ class TransitionLog (PersistedTransitionMixin ):
112+ pass
113+ ```
114+
115+ ### Register the model
116+
117+ ``` python
118+ DJANGO_FSM_LOG_CONCRETE_MODEL = ' poll.models.TransitionLog' # This model must inherit from django_fsm_log.models.PersistedTransition
119+ ```
120+
102121The app listens for the ` django_fsm.signals.post_transition ` signal and
103122creates a new record for each transition.
104123
105124To query the log:
106125
107126``` python
108- from django_fsm_log.models import StateLog
109- StateLog.objects.all()
127+ TransitionLog.objects.all()
110128# ...all recorded logs...
111129```
112130
@@ -125,11 +143,10 @@ For convenience there is a custom `for_` manager method to easily filter on the
125143
126144``` python
127145from my_app.models import Article
128- from django_fsm_log.models import StateLog
129146
130147article = Article.objects.all()[0 ]
131148
132- StateLog .objects.for_(article)
149+ TransitionLog .objects.for_(article)
133150# ...logs for article...
134151```
135152
@@ -157,7 +174,7 @@ With this the transition gets logged when the `by` kwarg is present.
157174
158175``` python
159176article = Article.objects.create()
160- article.submit(by = some_user) # StateLog .by will be some_user
177+ article.submit(by = some_user) # TransitionLog .by will be some_user
161178```
162179
163180### ` description ` Decorator
@@ -210,21 +227,31 @@ article.submit() # logged with "Article submitted" description
210227
211228There is an InlineForm available that can be used to display the history of changes.
212229
213- To use it expand your own ` AdminModel ` by adding ` StateLogInline ` to its inlines:
230+ To use it expand your own ` AdminModel ` by adding ` PersistedTransitionInline ` to its inlines:
214231
215232``` python
216233from django.contrib import admin
217- from django_fsm_log.admin import StateLogInline
234+ from django_fsm_log.admin import PersistedTransitionInline
218235
219236
220237@admin.register (FSMModel)
221238class FSMModelAdmin (admin .ModelAdmin ):
222- inlines = [StateLogInline]
239+ inlines = [PersistedTransitionInline]
240+ ```
241+
242+ ### Migration to Abstract model PersistedTransitionMixin
243+
244+ Once you defined your own model, you'll have to create the relevant migration to create the table.
245+
246+ ``` sh
247+ python manage.py makemigrations
223248```
224249
250+ Additionally you'd want to migrate the data from django_fsm_log.models.StateLog to your new table.
251+
225252### Advanced Usage
226253
227- You can change the behaviour of this app by turning on caching for StateLog records.
254+ You can change the behaviour of this app by turning on caching for PersistedTransition records.
228255Simply add ` DJANGO_FSM_LOG_STORAGE_METHOD = 'django_fsm_log.backends.CachedBackend' ` to your project's settings file.
229256It will use your project's default cache backend by default. If you wish to use a specific cache backend, you can add to
230257your project's settings:
@@ -233,22 +260,23 @@ your project's settings:
233260DJANGO_FSM_LOG_CACHE_BACKEND = ' some_other_cache_backend'
234261```
235262
236- The StateLog object is now available after the ` django_fsm.signals.pre_transition `
263+ The PersistedTransition object is now available after the ` django_fsm.signals.pre_transition `
237264signal is fired, but is deleted from the cache and persisted to the database after ` django_fsm.signals.post_transition `
238265is fired.
239266
240267This is useful if:
241268
242- - you need immediate access to StateLog details, and cannot wait until ` django_fsm.signals.post_transition `
269+ - you need immediate access to PersistedTransition details, and cannot wait until ` django_fsm.signals.post_transition `
243270has been fired
244- - at any stage, you need to verify whether or not the StateLog has been written to the database
271+ - at any stage, you need to verify whether or not the PersistedTransition has been written to the database
245272
246- Access to the pending StateLog record is available via the ` pending_objects ` manager
273+ Access to the pending PersistedTransition record is available via the ` pending_objects ` manager
247274
248275``` python
249- from django_fsm_log.models import StateLog
276+ from my_app.models import TransitionLog
277+
250278article = Article.objects.get(... )
251- pending_state_log = StateLog .pending_objects.get_for_object(article)
279+ pending_transition_logs = TransitionLog .pending_objects.get_for_object(article)
252280```
253281
254282## Contributing
0 commit comments