1

I want to implement a feature, similar to the one described in "company-goggles" question. Its answers suggest putting the value to filter against into user session, but I really dislike that and try to make it a part of URL instead.

To do this, I want to map any URL admin/company/*/ to just admin/, so I would be able to extract that value later in my admin.py models to apply the queryset filter against it. Unfortunately, my naive attempts to play with the URL routers failed. The following doesn't seem to work:

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/company/\w+/', admin.site.urls),
    url(r'^admin/',             admin.site.urls),
]

If I remove the second patterns, admin panel got at least displayed, but it reverses all links to admin/company/x/..., and I really have no idea where it takes that "x" from. Trying using include(admin.site.urls) with or withoutnamespace` parameter doesn't help either.

Is there a way to make link reverse work correctly?
Or may there be a conceptually better way to handle this issue?

Community
  • 1
  • 1
firegurafiku
  • 3,017
  • 1
  • 28
  • 37

0 Answers0