Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
37062c64
Unverified
Commit
37062c64
authored
May 30, 2020
by
Gautier D
Committed by
Florent Chehab
May 31, 2020
Browse files
feat(backend): create custom admin site
parent
c47e58bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/base_app/admin.py
View file @
37062c64
...
...
@@ -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"
,)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment