-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Deprecate StateLog model, to instead, bring your own model. #176
Draft
ticosax
wants to merge
10
commits into
jazzband:master
Choose a base branch
from
ticosax:gh-133-state-lessmodels
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c347e8b
Deprecate StateLog model, to instead bring your own model.
ticosax 0819cd2
Update README.md
ticosax f49a842
Update README.md
ticosax 88c3f07
Update django_fsm_log/admin.py
ticosax cd9854d
Update django_fsm_log/managers.py
ticosax 8a68343
Update django_fsm_log/managers.py
ticosax 89c1e25
Update django_fsm_log/managers.py
ticosax 97675b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 86aaa11
Update django_fsm_log/models.py
ticosax 9262180
Update django_fsm_log/models.py
ticosax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
from typing import List | ||
|
||
from appconf import AppConf | ||
from django.conf import settings # noqa: F401 | ||
|
||
|
||
class DjangoFSMLogConf(AppConf): | ||
STORAGE_METHOD = "django_fsm_log.backends.SimpleBackend" | ||
CACHE_BACKEND = "default" | ||
IGNORED_MODELS = [] | ||
IGNORED_MODELS: List[str] = [] | ||
CONCRETE_MODEL: str = "django_fsm_log.models.StateLog" | ||
|
||
class Meta: | ||
prefix = "django_fsm_log" | ||
holder = "django_fsm_log.conf.settings" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Generated by Django 2.1.5 on 2019-01-31 03:41 | ||
|
||
from django.db import migrations | ||
|
||
import django_fsm_log.managers | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,22 @@ | ||||||||
from warnings import warn | ||||||||
|
||||||||
from django.conf import settings | ||||||||
from django.contrib.contenttypes.fields import GenericForeignKey | ||||||||
from django.contrib.contenttypes.models import ContentType | ||||||||
from django.db import models | ||||||||
from django.utils.timezone import now | ||||||||
from django_fsm import FSMFieldMixin, FSMIntegerField | ||||||||
|
||||||||
from .conf import settings | ||||||||
from .managers import StateLogManager | ||||||||
from .managers import PersistedTransitionManager | ||||||||
|
||||||||
|
||||||||
class PersistedTransitionMixin(models.Model): | ||||||||
""" | ||||||||
Abstract class that should be subclassed by the host application. | ||||||||
Host projects should own the migrations and | ||||||||
can decide on their own primary key type. | ||||||||
""" | ||||||||
|
||||||||
class StateLog(models.Model): | ||||||||
timestamp = models.DateTimeField(default=now) | ||||||||
by = models.ForeignKey( | ||||||||
getattr(settings, "AUTH_USER_MODEL", "auth.User"), | ||||||||
|
@@ -26,9 +34,10 @@ class StateLog(models.Model): | |||||||
|
||||||||
description = models.TextField(blank=True, null=True) | ||||||||
|
||||||||
objects = StateLogManager() | ||||||||
objects = PersistedTransitionManager() | ||||||||
|
||||||||
class Meta: | ||||||||
abstract = True | ||||||||
get_latest_by = "timestamp" | ||||||||
|
||||||||
def __str__(self): | ||||||||
|
@@ -47,3 +56,15 @@ def get_state_display(self, field_name="state"): | |||||||
|
||||||||
def get_source_state_display(self): | ||||||||
return self.get_state_display("source_state") | ||||||||
|
||||||||
|
||||||||
class StateLog(PersistedTransitionMixin): | ||||||||
def __init__(self, *args, **kwargs): | ||||||||
warn( | ||||||||
"StateLog model has been deprecated, you should now bring your own model." | ||||||||
"\nPlease check the documentation at https://django-fsm-log.readthedocs.io/en/latest/" | ||||||||
"\nto know how to.", | ||||||||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: use more specific link. |
||||||||
DeprecationWarning, | ||||||||
stacklevel=2, | ||||||||
) | ||||||||
return super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from django.contrib import admin | ||
|
||
from django_fsm_log.admin import StateLogInline | ||
from django_fsm_log.admin import PersistedTransitionInline | ||
|
||
from .models import Article | ||
|
||
|
||
@admin.register(Article) | ||
class ArticleAdmin(admin.ModelAdmin): | ||
inlines = [StateLogInline] | ||
inlines = [PersistedTransitionInline] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have an example/snippet here that can be used as a base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it could be a nice addition, If I have to go through that path. I'll add it.
As of today I don't have incentive to migrate to an internal concrete model within the projects I maintain. It will come at some point, probably not as part of this PR though.