How will we can rewrite the UI and permission for the admin's panel?

Hallo, colleagues.
Which are our first steps for what will change (in to the admin panel) the:

  • admin panel UI?
  • user permission?

I don’t see the descript on this theme in doc.
Example if me nead to change the admin panel and making from him the user’s UI panel (let it be the user’s profile). The admin panel make splitted by the user roles & permissions.

That all possible?

It’s not really clear to me exactly what you’re trying to achieve here.

There are some customizations you can make in the admin to manage who can see what forms, but I got the impression you might be looking to do more than that.

That’s not the intent or purpose of the Django Admin.

Quoting from the first two paragraphs at The Django admin site | Django documentation | Django

The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.

While it might be possible to do what you’re looking to do here, it’s likely going to be more work to get the exact results you want than if you just went ahead and created your own views.

SImply, i want understand - Can i write the page of profile from/for project or not.
Take the any project. Example a marketplace and roles: admin; manager; user. Everyone, must have a big UI - from this roles.
User will have the pay-spiral.
MAnager must have the report graphics .

Now all from this made/created from an additional frontend-UI.

And )) me “sawing” this question (long time )

You can create any type of page you want.

You can limit access to any page using any criteria desired.

But I’m not following how this question has anything to do with the Django Admin.

If you’ve still got questions about this, it might be helpful if you narrowed it down to one specific situation so that you’re not trying to address ten different issues in one post.

No. We can closed this theme.
I only wanted to know - can in the panel itself or not . Thanks

I’m not entirely sure what you’re trying to do, maybe try using a translator to translate from your native language to english so that we can better understand your question and offer better help.

However, from what I gather (I think), You’re trying to use the Django Admin panel for different user types (User, Manager, etc) and reuse most of the admin so you create less custom templates right?

You can utilize the Groups for this - which basically means you’ll create Groups (aka Roles) and assign permissions to each group. For example, user group will not have the view_reports, add_report, change_report, and delete_report permissions.

Naturallry, if a logged in user does not have read/view permissions for a model, they won’t be able to access that page, it won’t even show up in the sidebar or in the app’s changelist page.

combine that with model specific template overrides for admin and you’ll be able to achieve what you’re trying to accomplish (again, this is based off what i gather from your questions). So let’s say you have an app name reports and a model named Report, you’ll want to create a template in templates/admin/<app_label>/<model_name_slug>.html which in this case would be templates/admin/report/report.html

Hope this helps. Cheers!

I always try to check my text through a translator (google) and/or depseek (I know my sentence syntax is problematic and I trying to learn it. I wonder how bad it is). :slight_smile:

I published this post to understand, for example:

  • I can add a matplotlib graph;
  • change the color scheme

Note: in the admin panel (basic) “from django.contrib import admin”. (http://127.1.1.1:8000/admin/) without using additional templates in

root
 |
 └── templates/
 │   |   └── layout/
 │   |   |   └── *.html
 │   |   └── index.html

That clarifies things a lot. I think I understand what you’re trying to accomplish, and yes you can do it without creating extra templates using the Model Admin.


Changing the admin color scheme is also achievable without touching project-level templates. You can include your own CSS by defining Media.css in your ModelAdmin


Django admin allows you to register extra URLs inside your ModelAdmin. One of those URLs can run matplotlib in-memory and return a PNG. The admin page will simply show that image when you visit the URL.

The process looks like this, in plain steps:

A ModelAdmin gets a new path like /admin/mychart/.
That path runs a Python function that generates a chart inside RAM, not on disk.
The function returns the image as an HttpResponse.
You open the URL in the browser, and boom — chart appears like a wizard-drawn talisman, no template required.

from django.contrib import admin
from django.urls import path
from django.http import HttpResponse
import matplotlib.pyplot as plt
import io

class MyModelAdmin(admin.ModelAdmin):
    change_list_template = None  # still no template override, we’re not using it

    # 1. Add extra URL inside this admin
    def get_urls(self):
        urls = super().get_urls()
        extra = [
            path("mychart/", self.admin_site.admin_view(self.render_chart))
        ]
        return extra + urls

    # 2. Function that generates a chart in memory and returns it
    def render_chart(self, request):
        buffer = io.BytesIO()

        # Generate a basic chart
        plt.figure()
        plt.plot([0, 1, 2, 3], [10, 5, 8, 12])
        plt.title("Ranking Pokemon Beasts")
        plt.savefig(buffer, format="png")
        plt.close()

        buffer.seek(0)
        return HttpResponse(buffer.getvalue(), content_type="image/png")

# 3. Register any model with this admin
from .models import MyModel
admin.site.register(MyModel, MyModelAdmin)

The question was: is it possible to overwrite the admin panel code (the admin panel code we get after running “django-admin startproject” or “python manage.py startapp”) and where to start?

or
For example, how can I also get matplotlib from the URL (http://127.1.1.1:8000/admin/)?
This is
When “urls.py” contains

from django.contrib import admin
urlpatterns = [
    path("admin/", admin.site.urls),
]

)))

To do that, you’ll have to create your own AdminSite - different from the default admin site.

In your app’s admin.py file or elsewhere, create a subclass of the admin.AdminSite class.

# assuming yourapp/site.py

from django.contrib import admin

class YourCustomAdminSite(admin.AdminSite):
    # you can override the default admin interface that was created by django 
    # with this, but it also means you'll have to change your project/urls.py and 
    # register your models with this admin site instance

    site_header = "Custom Admin"
    site_title = "Custom Admin"
    index_title = "Custom Admin"


# now create an instance of your new admin site

custom_admin_site = YourCustomAdminSite()


# assuming yourapp/admin.py
from .models import YourModel
from .site import custom_admin_site


custom_admin_site.register(YourModel)


# in your project root's urls.py
from django.urls import path
from yourapp.site import custom_admin_site

urlpatterns = [
     path('admin/', custom_admin_site.urls), # replaces admin.site.urls
]

Note that even though you’ve now created a custom AdminSite, it’ll still use the default Django mechanism for creating admin pages and its default templates.

You’ll need to create a custom templates/admin folder with templates that override

-– base.html
-– base_site.html
-– index.html
-– …etc


In you case, you want the matplotlib from http://localhost:8000/admin/ - to achieve this, you’ll need to override the index_view in your custom_admin_site class so that you can pass in the context of the matplotlib instance


# ...previous code
from django.template.response import TemplateResponse


class YourCustomAdmin(admin.AdminSite):
    # previous code
    
    def index_view(self, request, extra_context=None, **kwargs):
        # now you can create your matplotlib and render
        context:dict = self.each_context(request) # get the default context
        template = "admin/index.html" # or your custom template

        context.update({
            'matplotlib': self.your_matplotlib_func(),
            # **extra_context if extra_context 
        })
        
        return TemplateResponse(request, template, context)