InvenTree/InvenTree/common/admin.py

59 lines
1.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2019-09-02 22:30:14 +00:00
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
2021-11-03 14:06:57 +00:00
import common.models
2019-09-02 23:07:03 +00:00
class SettingsAdmin(ImportExportModelAdmin):
list_display = ('key', 'value')
2021-11-11 11:39:31 +00:00
def get_readonly_fields(self, request, obj=None):
"""
Prevent the 'key' field being edited once the setting is created
"""
if obj:
2021-11-12 04:42:53 +00:00
return ['key']
2021-11-11 11:39:31 +00:00
else:
return []
2021-07-22 21:46:31 +00:00
class UserSettingsAdmin(ImportExportModelAdmin):
list_display = ('key', 'value', 'user', )
2021-11-11 11:39:31 +00:00
def get_readonly_fields(self, request, obj=None):
"""
Prevent the 'key' field being edited once the setting is created
"""
if obj:
2021-11-12 04:42:53 +00:00
return ['key']
2021-11-11 11:39:31 +00:00
else:
return []
2021-07-22 21:46:31 +00:00
2021-11-03 14:06:57 +00:00
class NotificationEntryAdmin(admin.ModelAdmin):
list_display = ('key', 'uid', 'updated', )
class NotificationMessageAdmin(admin.ModelAdmin):
list_display = ('age_human', 'user', 'category', 'name', 'read', 'target_object', 'source_object', )
list_filter = ('category', 'read', 'user', )
search_fields = ('name', 'category', 'message', )
2021-11-03 14:06:57 +00:00
admin.site.register(common.models.InvenTreeSetting, SettingsAdmin)
admin.site.register(common.models.InvenTreeUserSetting, UserSettingsAdmin)
admin.site.register(common.models.NotificationEntry, NotificationEntryAdmin)
admin.site.register(common.models.NotificationMessage, NotificationMessageAdmin)