jsocol / django-adminplus

Easily add custom views to the Django admin.
BSD 3-Clause "New" or "Revised" License
591 stars 79 forks source link

Django 2.x support #61

Closed stavlocker closed 11 months ago

stavlocker commented 6 years ago

Hi, I'd love to see django 2.x get integrated. As far as I can tell there's a PR waiting from January 2018 https://github.com/jsocol/django-adminplus/pull/58 to support 1.10+ that just doesn't get merged. This package renders unusable for me unless something is done to support 2.1. I'm doing everything by the book and still getting the infamous django.urls.exceptions.NoReverseMatch: Reverse for 'app_list' with keyword arguments '{'app_label': ''}' not found.

jsocol commented 5 years ago

I've been digging into this and there's been a kind of surprising amount of movement in the admin config area of 2.0 and 2.1 and I'm not sure the best route forward here.

  1. 2.0 changed a bunch of things around URL conf and how they get installed.
  2. There are some details around installing SimpleAdminConfig vs AdminConfig
  3. In 2.1, there's an option to create a custom AdminConfig that can override the default admin site
oliwarner commented 5 years ago

Great point there @jsocol! I just wrote this little appconfig module for our purposes. Note that this is doing more than just installing AdminPlus, it sets titles, wraps with a login required so we can use a central single, central login view.

admin.py:

from django.contrib.admin.apps import AdminConfig
from django.contrib.auth.decorators import login_required

class AdminPlusConfig(AdminConfig):
    default_site = 'adminplus.sites.AdminSitePlus'

    def ready(self):
        super().ready()

        self.module.site.site_title = self.module.site.site_header = 'Our Magic Admin'
        self.module.site.login = login_required(self.module.site.login)

settings.py:

INSTALLED_APPS = [
    'admin.AdminPlusConfig',
    'adminplus',  # needed unless you make that AppConfig "poison" the template dirs
]

urls.py:

from django.contrib import admin
urlpatterns = [
    path('admin/', include(admin.site.urls[:2], admin.site.urls[2])),
]

The site.urls is the only bit that's a bit funky now. If you could make that a Django 2-sensitive @property, that would really minimise the amount of hacking to get this in. Hell, you could even provide a little AppConfig, makes installation just two lines in INSTALLED_APPS.

pkrefta commented 4 years ago

Hi @jsocol - are there any plans to support Django 2.x ?

jsocol commented 4 years ago

I would love to get this updated. I imagine this situation described in this comment has gotten better since we no longer have to worry about 2.0 and 2.1, only 2.2 and 3.0. I have not been working in Django day to day recently, though, so I'm not sure how easy it will be to support both 2.2 and 3.0.

I'm extremely open to patches that bring adminplus up to date with 2.2's— and hopefully 3.0's—admin module changes. I hope that the differences are smaller than existed between 2.{0,1,2}.

jsocol commented 11 months ago

The code on main is now tested against Django 3.2, 4.2, and 5.0 (plus some others) and seems to be working. I'm working on cutting a new release today