[Django] #32324: Adding more blocks to the contrib.admin site

39 views
Skip to first unread message

Django

unread,
Jan 5, 2021, 10:59:25 AM1/5/21
to django-...@googlegroups.com
#32324: Adding more blocks to the contrib.admin site
-------------------------------------+-------------------------------------
Reporter: Muskan | Owner: nobody
Vaswan |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 3.1
contrib.admin |
Severity: Normal | Keywords: admin customize
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 1 |
-------------------------------------+-------------------------------------
The Django admin template can be overridden and extended by the user.
However, flexibility to customize the admin page can be increased by
putting larger chunks of code inside a `{% block ... %}... {% endblock
%}`. This will be useful as it will allow the user to completely rewrite
an entire segment of the page without having to override smaller elements
or the entire template.

For example, the user can overwrite the entire navbar if the header was
put inside `{% block header %}` simply by extending the template.

Refer to this conversation [https://groups.google.com/g/django-
developers/c/Q8I-0-2Sn4M] (point 2) for the full discussion

--
Ticket URL: <https://code.djangoproject.com/ticket/32324>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 5, 2021, 10:59:44 AM1/5/21
to django-...@googlegroups.com
#32324: Adding more blocks to the contrib.admin site
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:

Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Muskan Vaswan):

* owner: nobody => Muskan Vaswan
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:1>

Django

unread,
Jan 5, 2021, 11:53:36 AM1/5/21
to django-...@googlegroups.com
#32324: Adding more blocks to the contrib.admin site.

-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: invalid

Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => invalid


Comment:

> For example, the user can overwrite the entire navbar if the header was
put inside {% block header %} simply by extending the template.

The navigation sidebar is already in a separate block `nav-sidebar` and
use a separate template, so it's easy to customize, see
[https://code.djangoproject.com/ticket/31856?cnum_edit=1#comment:1
comment]. Also, `header` already contains blocks for each element so I
don't see how adding another `block` around existing blocks can increase
flexibility.

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:2>

Django

unread,
Jan 5, 2021, 1:18:15 PM1/5/21
to django-...@googlegroups.com
#32324: Adding more blocks to the contrib.admin site.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: invalid
Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Muskan Vaswan):

That was an example... Also adding the entire header inside a block
improves flexibility as it allows the user to change the entire topbar in
one go rather changing singular elements. Not to mention currently if the
user wants to make an entirely new topbar... ideally making the old one
disappear entirely they would have to override and extend two files, that
is, base_site.html for (branding block) and base.html (for the user_tools
block) both and it still doesn't entirely dissapear. Which could simply be
accomplished by adding a block for the entire header and the user could
simply extend the base.html and `{% block header %}{% endblock %}`.
Another example is if the user wants to change the add_url for a
particular model having more blocks would be very helpful.
Replying to [comment:2 Mariusz Felisiak]:


> > For example, the user can overwrite the entire navbar if the header
was put inside {% block header %} simply by extending the template.
>

> The navigation sidebar is already in a separate block `nav-sidebar` and
use a separate template, so it's easy to customize, see
[https://code.djangoproject.com/ticket/31856?cnum_edit=1#comment:1
comment]. Also, `header` already contains blocks for each element so I
don't see how adding another `block` around existing blocks can increase
flexibility.

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:3>

Django

unread,
Jan 5, 2021, 2:17:57 PM1/5/21
to django-...@googlegroups.com
#32324: Adding more blocks to the contrib.admin site.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: needsinfo

Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* resolution: invalid => needsinfo


Comment:

Ticket described as ''"adding more blocks"'' cannot be accepted, it's too
generic. You need to describe a concrete issue and use case. Maybe you
should [https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#set-up-
your-projects-admin-template-directories "Set up your projects admin
template directories"] for your use case.

> Another example is if the user wants to change the add_url for a
particular model having more blocks would be very helpful.

I don't think that templates are appropriate place for such logic.

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:4>

Django

unread,
Jan 6, 2021, 7:20:00 AM1/6/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.

-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: needsinfo
Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------

Old description:

> The Django admin template can be overridden and extended by the user.
> However, flexibility to customize the admin page can be increased by
> putting larger chunks of code inside a `{% block ... %}... {% endblock
> %}`. This will be useful as it will allow the user to completely rewrite
> an entire segment of the page without having to override smaller elements
> or the entire template.
>
> For example, the user can overwrite the entire navbar if the header was
> put inside `{% block header %}` simply by extending the template.
>
> Refer to this conversation [https://groups.google.com/g/django-
> developers/c/Q8I-0-2Sn4M] (point 2) for the full discussion

New description:

=== Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.

=== Existing method

to Overwrite the top nav-bar without having to overwrite the entire
template of base.html, the user currently has to add the

{{{
{% extends "admin/base_site.html" %}
{% load static %}
{% block branding %}
{% endblock %}
}}}

to admin/base_site.html and`

{{{
{% extends "admin/base.html" %}
{% load static %}
{% block usertools %}
{% endblock %}
}}}
to admin/base.html.
No other method, other than overwriting the entire template exists.

=== Issue with Existing method

1. Even after doing the above the top-bar doesn't entirely disappear dude
to the CSS applied on the <div> with the id of header
(Image attached)

2. The user must extend two separate files to even make this happen.

=== Solution

The simple solution is to wrap the entire header class using {% block ...
%}. So the final django/admin/base.html would have:

{{{
<!-- Header -->
{% block header %}
<div id="header">
...
</div>
{% endblock %}
<!-- END Header -->

}}}

=== Final Result
The user will be able to overwrite the default blue-green nav-bar
*entirely* by adding


{{{
{% extends "admin/base.html" %}
{% load static %}


{% block header %}
{% endblock %}
}}}

to admin/base.html.

--

Comment (by Muskan Vaswan):

In consideration of that, I wrote a more specific and comprehensive Issue.
I hope this makes it more clear.

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:5>

Django

unread,
Jan 6, 2021, 10:12:34 AM1/6/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: needsinfo
Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Muskan Vaswan):

* Attachment "Screen Shot 2021-01-06 at 5.02.36 PM.png" added.

Django

unread,
Jan 7, 2021, 3:59:56 AM1/7/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: new

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: admin customize | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: closed => new
* resolution: needsinfo =>


Comment:

Thanks for the more detailed info. I will reopen to triage again.

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:6>

Django

unread,
Jan 7, 2021, 10:03:00 AM1/7/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: admin customize | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

Hmmm. I'm a bit sceptical that very many people want to remove the header
entirely, but I agree that a single block would make that feasible.

> Even after doing the above the top-bar doesn't entirely disappear dude
to the CSS applied on the <div> with the id of header

Query: an amount of CSS resolves that no?

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:7>

Django

unread,
Jan 7, 2021, 10:28:29 AM1/7/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: admin customize | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------

Old description:

> === Use case
> Allowing the user to overwrite the Top Navigation Bar od the admin page.
>
> === Existing method
>
> to Overwrite the top nav-bar without having to overwrite the entire
> template of base.html, the user currently has to add the
>
> {{{
> {% extends "admin/base_site.html" %}
> {% load static %}
> {% block branding %}
> {% endblock %}
> }}}
>
> to admin/base_site.html and`
>
> {{{
> {% extends "admin/base.html" %}
> {% load static %}
> {% block usertools %}
> {% endblock %}
> }}}
> to admin/base.html.
> No other method, other than overwriting the entire template exists.
>
> === Issue with Existing method
>

> 1. Even after doing the above the top-bar doesn't entirely disappear dude


> to the CSS applied on the <div> with the id of header

> (Image attached)
>
> 2. The user must extend two separate files to even make this happen.
>
> === Solution
>
> The simple solution is to wrap the entire header class using {% block ...
> %}. So the final django/admin/base.html would have:
>
> {{{
> <!-- Header -->
> {% block header %}
> <div id="header">
> ...
> </div>
> {% endblock %}
> <!-- END Header -->
>
> }}}
>
> === Final Result
> The user will be able to overwrite the default blue-green nav-bar
> *entirely* by adding
>

> {{{
> {% extends "admin/base.html" %}
> {% load static %}
> {% block header %}
> {% endblock %}
> }}}
> to admin/base.html.

New description:

=== Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.

=== Existing method

to Overwrite the top nav-bar without having to overwrite the entire
template of base.html, the user currently has to add the

{{{
{% extends "admin/base_site.html" %}
{% load static %}
{% block branding %}
{% endblock %}
}}}

to admin/base_site.html and`

{{{
{% extends "admin/base.html" %}
{% load static %}
{% block usertools %}
{% endblock %}
}}}
to admin/base.html.
No other method, other than overwriting the entire template exists.

=== Issue with Existing method

1. Even after doing the above, the top-bar doesn't entirely disappear due


to the CSS applied on the <div> with the id of header

(Image attached)

2. The user must extend two separate files to even make this happen.

=== Solution

The simple solution is to wrap the entire header class using {% block ...
%}. So the final django/admin/base.html would have:

{{{
<!-- Header -->
{% block header %}
<div id="header">
...
</div>
{% endblock %}
<!-- END Header -->

}}}

=== Final Result
The user will be able to overwrite the default blue-green nav-bar
*entirely* by adding


{{{
{% extends "admin/base.html" %}
{% load static %}
{% block header %}
{% endblock %}
}}}
to admin/base.html.

--

Comment (by Muskan Vaswan):

Replying to [comment:7 Carlton Gibson]:


> Hmmm. I'm a bit sceptical that very many people want to remove the
header entirely, but I agree that a single block would make that feasible.
>
> > Even after doing the above the top-bar doesn't entirely disappear dude
to the CSS applied on the <div> with the id of header
>
> Query: an amount of CSS resolves that no?

Yes, adding CSS to make would surely make it disappear, but I'm not sure
if that would be the best way to do it, but again, that's just what I
think.
About the first point, I have come across many occasions when I needed to
replace the admin top-nav and personally, I don't think its that uncommon
to have a themed top-bar that you want to use throughout the website.
At the same time, I agree, it's not a pressing issue by any means.
I guess it's just a matter of deciding whether making something like this
more convenient for the user justifies adding another block...

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:8>

Django

unread,
Jan 10, 2021, 3:10:42 AM1/10/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: admin customize | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Muskan Vaswan):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:9>

Django

unread,
Jan 18, 2021, 2:56:40 PM1/18/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: admin customize | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:10>

Django

unread,
Jan 19, 2021, 6:52:52 AM1/19/21
to django-...@googlegroups.com
#32324: Wrapping the header in base.html of contrib.abmin in {% blocks %}.
-------------------------------------+-------------------------------------
Reporter: Muskan Vaswan | Owner: Muskan
Type: | Vaswan
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: fixed

Keywords: admin customize | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"ab7478d1d4aeaa816cd723793ae9e8325ad11c33" ab7478d]:
{{{
#!CommitTicketReference repository=""
revision="ab7478d1d4aeaa816cd723793ae9e8325ad11c33"
Fixed #32324 -- Added template block to override the admin site header.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:11>

Reply all
Reply to author
Forward
0 new messages