Changes between Version 1 and Version 2 of Ticket #32692


Ignore:
Timestamp:
Apr 28, 2021, 6:35:49 AM (3 years ago)
Author:
Mariusz Felisiak
Comment:

IMO it's a duplicate of #30402. You should customize a default admin site inside a main project directory (like described in the documentation) not in an app.

Please feel-free to send a PR with docs adjustments if you think we should make it clearer.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32692

    • Property Component Core (Other)contrib.admin
    • Property Resolutionduplicate
    • Property Status newclosed
  • Ticket #32692 – Description

    v1 v2  
    77- `python manage.py createsuperuser`
    88- Put a template in `myproject/templates/admin/base_site.html`
    9 {{{
    10 {% extends 'admin/base_site.html' %}
    11 
    12 {% block branding %}
    13 Template test
    14 {% endblock %}
    15 }}}
    169- Add `myproject` to `INSTALLED_APPS`
    17 {{{#!python
    18 INSTALLED_APPS = [
    19     'myproject',
    20 
    21     'django.contrib.admin',
    22     'django.contrib.auth',
    23     'django.contrib.contenttypes',
    24     'django.contrib.sessions',
    25     'django.contrib.messages',
    26     'django.contrib.staticfiles',
    27 ]
    28 }}}
    2910- `python manage.py runserver` works, I can access the admin site and see the changes in templates
    3011- Follow the guide to override the default admin site, https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-default-admin-site, this is, create `myproject/admin.py`, `myproject/apps.py` and modify `settings.py`.
    31 {{{#!python
    32 # myproject/admin.py
    33 from django.contrib import admin
    34 
    35 class MyAdminSite(admin.AdminSite):
    36     index_title = 'Test'
    37 
    38 
    39 # myproject/apps.py
    40 from django.contrib.admin.apps import AdminConfig
    41 
    42 class MyAdminConfig(AdminConfig):
    43     default_site = 'myproject.admin.MyAdminSite'
    44 
    45 
    46 # myproject/settings.py
    47 INSTALLED_APPS = [
    48     'myproject',
    49 
    50     'myproject.apps.MyAdminConfig',  # 'django.contrib.admin',
    51     'django.contrib.auth',
    52     'django.contrib.contenttypes',
    53     'django.contrib.sessions',
    54     'django.contrib.messages',
    55     'django.contrib.staticfiles',
    56 ]
    57 }}}
    5812- `python manage.py runserver`
    5913
     
    6822**Workaroud**
    6923- use `app-admin.py` instead of `apps.py` when following the documentation to override the default admin site
    70 {{{#!python
    71 from django.contrib.admin.apps import AdminConfig
    72 
    73 class MyAdminConfig(AdminConfig):
    74     default_site = 'myproject.admin.MyAdminSite'
    75 }}}
    7624- adjust settings.py: `'myproject.apps-admin.MyAdminConfig'` in INSTALLED_APPS
    77 {{{#!python
    78 INSTALLED_APPS = [
    79     'myproject',
    80 
    81     'myproject.apps-admin.MyAdminConfig',  # 'django.contrib.admin',
    82     'django.contrib.auth',
    83     'django.contrib.contenttypes',
    84     'django.contrib.sessions',
    85     'django.contrib.messages',
    86     'django.contrib.staticfiles',
    87 ]
    88 }}}
    89 - works with Django 3.2 now!
     25- works with Django 3.2
Back to Top