Branch master was renamed to main.

khaganat-web/pwdb/admin.py

27 lines
789 B
Python
Raw Permalink Normal View History

2019-07-27 15:17:21 +00:00
from django.contrib import admin
from .models import SharedPassword, SharedPasswordAccess
from .forms import NewSharedPasswordForm, EditSharedPasswordForm
class SharedPasswordAdmin(admin.ModelAdmin):
form = NewSharedPasswordForm
exclude = ["iv", "encrypted_password"]
list_display = ("name", "users")
def get_form(self, request, obj=None, **kwargs):
if obj is None:
kwargs["form"] = NewSharedPasswordForm
else:
kwargs["form"] = EditSharedPasswordForm
return super().get_form(request, obj, **kwargs)
admin.site.register(SharedPassword, SharedPasswordAdmin)
class SharedPasswordAccessAdmin(admin.ModelAdmin):
list_display = ("password", "user")
admin.site.register(SharedPasswordAccess, SharedPasswordAccessAdmin)