This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-05-06 22:05:10 +00:00
|
|
|
"""passbook core admin"""
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-05-06 22:05:10 +00:00
|
|
|
from django.apps import AppConfig, apps
|
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.admin.sites import AlreadyRegistered
|
|
|
|
from guardian.admin import GuardedModelAdmin
|
|
|
|
from structlog import get_logger
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-05-06 22:05:10 +00:00
|
|
|
LOGGER = get_logger()
|
|
|
|
|
|
|
|
|
|
|
|
def admin_autoregister(app: AppConfig):
|
|
|
|
"""Automatically register all models from app"""
|
|
|
|
for model in app.get_models():
|
|
|
|
try:
|
|
|
|
admin.site.register(model, GuardedModelAdmin)
|
|
|
|
except AlreadyRegistered:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
for app in apps.get_app_configs():
|
|
|
|
if app.label.startswith("passbook_"):
|
|
|
|
LOGGER.debug("Registering application for dj-admin", app=app.label)
|
|
|
|
admin_autoregister(app)
|