from django.contrib import admin from django.db.models import Model from django.urls import reverse def admin_url(model: type[Model], view: str, *args, site=None, **kwargs) -> str: return reverse(admin_url_name(model, view, site=site), args=args, kwargs=kwargs) def admin_url_name(model: type[Model], view: str, *, site=None) -> str: namespace = (site or admin.site).name view_name = admin_view_name(model, view) return f'{namespace}:{view_name}' def admin_view_name(model: type[Model], view: str) -> str: return f'{model._meta.app_label}_{model._meta.model_name}_{view}'