Unverified Commit 37062c64 authored by Gautier D's avatar Gautier D Committed by Florent Chehab
Browse files

feat(backend): create custom admin site

parent c47e58bd
......@@ -2,15 +2,31 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm
from rest_framework.authtoken.admin import TokenAdmin
from django.urls import path
from .models import User
from base_app.models import User
# create a custom admin site
from base_app.views import trigger_cron
class CustomAdminSite(admin.AdminSite):
Custom admin site used to add a trigger_cron view
on the admin site provided by django
def get_urls(self):
urls = super().get_urls()
urls += [path("trigger_cron/", self.admin_view(trigger_cron))]
return urls
admin_site = CustomAdminSite(name="custom_admin_site")
# Handling of the registration of the custom User model to make sure
# we can see all the fields.
# taken from: https://stackoverflow.com/a/15013810
class CustomUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User
......@@ -27,7 +43,7 @@ class CustomUserAdmin(UserAdmin):
admin.site.register(User, CustomUserAdmin)
admin_site.register(User, CustomUserAdmin)
# Pour la génération de token dans l'administration du site.
TokenAdmin.raw_id_fields = ("user",)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment