2015-02-13 01:14:19 +08:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.admin import UserAdmin
|
2018-12-08 06:52:28 +08:00
|
|
|
from django.urls import path
|
2015-02-13 01:14:19 +08:00
|
|
|
|
|
|
|
site = admin.AdminSite(name="custom_user_admin")
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserAdmin(UserAdmin):
|
2021-05-20 03:07:48 +08:00
|
|
|
def log_change(self, request, obj, message):
|
2015-02-13 01:14:19 +08:00
|
|
|
# LogEntry.user column doesn't get altered to expect a UUID, so set an
|
|
|
|
# integer manually to avoid causing an error.
|
2015-09-03 08:50:34 +08:00
|
|
|
original_pk = request.user.pk
|
2015-02-13 01:14:19 +08:00
|
|
|
request.user.pk = 1
|
2021-05-20 03:07:48 +08:00
|
|
|
super().log_change(request, obj, message)
|
2015-09-03 08:50:34 +08:00
|
|
|
request.user.pk = original_pk
|
2015-02-13 01:14:19 +08:00
|
|
|
|
2016-11-13 01:11:23 +08:00
|
|
|
|
2015-02-13 01:14:19 +08:00
|
|
|
site.register(get_user_model(), CustomUserAdmin)
|
|
|
|
|
2015-05-19 17:10:04 +08:00
|
|
|
urlpatterns = [
|
2018-12-08 06:52:28 +08:00
|
|
|
path("admin/", site.urls),
|
2015-02-13 01:14:19 +08:00
|
|
|
]
|