Tweaks for settings admin views

This commit is contained in:
Oliver 2021-11-11 22:39:31 +11:00
parent d4db750d2f
commit 03aa9bc9b0
2 changed files with 22 additions and 0 deletions

View File

@ -12,11 +12,31 @@ class SettingsAdmin(ImportExportModelAdmin):
list_display = ('key', 'value')
def get_readonly_fields(self, request, obj=None):
"""
Prevent the 'key' field being edited once the setting is created
"""
if obj:
return ['key',]
else:
return []
class UserSettingsAdmin(ImportExportModelAdmin):
list_display = ('key', 'value', 'user', )
def get_readonly_fields(self, request, obj=None):
"""
Prevent the 'key' field being edited once the setting is created
"""
if obj:
return ['key',]
else:
return []
class NotificationEntryAdmin(admin.ModelAdmin):

View File

@ -63,6 +63,8 @@ class BaseInvenTreeSetting(models.Model):
Enforce validation and clean before saving
"""
self.key = str(self.key).upper()
self.clean()
self.validate_unique()