-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide InlineForm to display transitions on admin
- Loading branch information
Showing
6 changed files
with
97 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.contrib.contenttypes.admin import GenericTabularInline | ||
from django.db.models import F | ||
|
||
from .models import StateLog | ||
|
||
|
||
__all__ = ('StateLogInline',) | ||
|
||
|
||
class StateLogInline(GenericTabularInline): | ||
model = StateLog | ||
can_delete = False | ||
|
||
def has_add_permission(self, request): | ||
return False | ||
|
||
def has_change_permission(self, request, obj=None): | ||
return True | ||
|
||
fields = ( | ||
'transition', | ||
'state', | ||
'by', | ||
'timestamp', | ||
) | ||
|
||
def get_readonly_fields(self, request, obj=None): | ||
return self.fields | ||
|
||
def get_queryset(self, request): | ||
return super(StateLogInline, self).get_queryset( | ||
request | ||
).order_by(F('timestamp').desc()) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.contrib import admin | ||
from django_fsm_log.admin import StateLogInline | ||
|
||
from .models import Article | ||
|
||
|
||
class ArticleAdmin(admin.ModelAdmin): | ||
inlines = [StateLogInline] | ||
|
||
|
||
admin.site.register(Article, ArticleAdmin) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
try: | ||
from django.urls import reverse | ||
except ImportError: | ||
# django<=1.10 | ||
from django.core.urlresolvers import reverse | ||
|
||
|
||
def test_state_log_inline_django2(article, admin_client, admin_user): | ||
article.submit(by=admin_user) | ||
article.publish(by=admin_user) | ||
url = reverse('admin:tests_article_change', args=(article.pk,)) | ||
response = admin_client.get(url) | ||
assert response.status_code == 200 | ||
assert '{} - submit'.format(article).encode() in response.content | ||
assert '{} - publish'.format(article).encode() in response.content |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
try: | ||
from django.urls import path | ||
from django.contrib import admin | ||
|
||
urlpatterns = [path('admin', admin.site.urls)] | ||
except ImportError: | ||
# django < 2.0 | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
|
||
urlpatterns = [url(r'^admin/', include(admin.site.urls))] |