1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

46 lines
1.2 KiB
Python
Raw Normal View History

2017-03-28 12:19:08 -04:00
from django import forms
2017-03-07 17:17:39 -05:00
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as UserAdmin_
from django.contrib.auth.models import User
2017-03-07 17:17:39 -05:00
2020-04-23 15:53:43 -04:00
from .models import Token, UserConfig
2017-03-07 17:17:39 -05:00
# Unregister the built-in UserAdmin so that we can use our custom admin view below
admin.site.unregister(User)
2020-04-23 15:53:43 -04:00
class UserConfigInline(admin.TabularInline):
model = UserConfig
readonly_fields = ('data',)
can_delete = False
verbose_name = 'Preferences'
@admin.register(User)
class UserAdmin(UserAdmin_):
list_display = [
'username', 'email', 'first_name', 'last_name', 'is_superuser', 'is_staff', 'is_active'
]
2020-04-23 15:53:43 -04:00
inlines = (UserConfigInline,)
2017-03-28 12:19:08 -04:00
class TokenAdminForm(forms.ModelForm):
key = forms.CharField(
required=False,
help_text="If no key is provided, one will be generated automatically."
)
2017-03-28 12:19:08 -04:00
class Meta:
fields = [
'user', 'key', 'write_enabled', 'expires', 'description'
]
2017-03-28 12:19:08 -04:00
model = Token
@admin.register(Token)
2017-03-07 17:17:39 -05:00
class TokenAdmin(admin.ModelAdmin):
2017-03-28 12:19:08 -04:00
form = TokenAdminForm
list_display = [
'key', 'user', 'created', 'expires', 'write_enabled', 'description'
]