2015-02-12 18:14:19 +01:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.admin import UserAdmin
|
2018-12-07 23:52:28 +01:00
|
|
|
from django.urls import path
|
2015-02-12 18:14:19 +01:00
|
|
|
|
|
|
|
site = admin.AdminSite(name="custom_user_admin")
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserAdmin(UserAdmin):
|
2021-05-19 21:07:48 +02:00
|
|
|
def log_change(self, request, obj, message):
|
2015-02-12 18:14:19 +01: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 02:50:34 +02:00
|
|
|
original_pk = request.user.pk
|
2015-02-12 18:14:19 +01:00
|
|
|
request.user.pk = 1
|
2021-05-19 21:07:48 +02:00
|
|
|
super().log_change(request, obj, message)
|
2015-09-03 02:50:34 +02:00
|
|
|
request.user.pk = original_pk
|
2015-02-12 18:14:19 +01:00
|
|
|
|
2016-11-12 18:11:23 +01:00
|
|
|
|
2015-02-12 18:14:19 +01:00
|
|
|
site.register(get_user_model(), CustomUserAdmin)
|
|
|
|
|
2015-05-19 11:10:04 +02:00
|
|
|
urlpatterns = [
|
2018-12-07 23:52:28 +01:00
|
|
|
path("admin/", site.urls),
|
2015-02-12 18:14:19 +01:00
|
|
|
]
|