Skip to content

Commit f09d1f3

Browse files
committed
admin panel 'created at' time is made to aware of the timezone
1 parent b8b1307 commit f09d1f3

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dist
88
.coding-ide
99
dev.db
1010
build
11-
11+
.eggs

dev_env/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
# Internationalization
109109
# https://docs.djangoproject.com/en/2.1/topics/i18n/
110110

111-
LANGUAGE_CODE = 'zh-hans'
111+
LANGUAGE_CODE = 'en'
112112

113113
TIME_ZONE = 'UTC'
114114

django_db_logger/admin.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from django.contrib import admin
5+
from django.utils import timezone
56
from django.utils.html import format_html
67

78
from django_db_logger.config import DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE
@@ -10,8 +11,8 @@
1011

1112
class StatusLogAdmin(admin.ModelAdmin):
1213
list_display = ('colored_msg', 'traceback', 'create_datetime_format')
13-
list_display_links = ('colored_msg', )
14-
list_filter = ('level', )
14+
list_display_links = ('colored_msg',)
15+
list_filter = ('level',)
1516
list_per_page = DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE
1617

1718
def colored_msg(self, instance):
@@ -22,14 +23,16 @@ def colored_msg(self, instance):
2223
else:
2324
color = 'red'
2425
return format_html('<span style="color: {color};">{msg}</span>', color=color, msg=instance.msg)
26+
2527
colored_msg.short_description = 'Message'
2628

2729
def traceback(self, instance):
2830
return format_html('<pre><code>{content}</code></pre>', content=instance.trace if instance.trace else '')
2931

3032
def create_datetime_format(self, instance):
31-
return instance.create_datetime.strftime('%Y-%m-%d %X')
33+
return timezone.localtime(instance.create_datetime).strftime('%Y-%m-%d %X')
34+
3235
create_datetime_format.short_description = 'Created at'
3336

3437

35-
admin.site.register(StatusLog, StatusLogAdmin)
38+
admin.site.register(StatusLog, StatusLogAdmin)

0 commit comments

Comments
 (0)