Fix import in Django 2.0
Because the URL mechanism has changed in Django 2.0, the RegexURLResolver has been renamed.
This commit is contained in:
@@ -11,16 +11,22 @@ from django.core.exceptions import PermissionDenied, ImproperlyConfigured
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http import Http404, HttpResponseRedirect
|
from django.http import Http404, HttpResponseRedirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls import RegexURLResolver
|
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from polymorphic.utils import get_base_polymorphic_model
|
from polymorphic.utils import get_base_polymorphic_model
|
||||||
from .forms import PolymorphicModelChoiceForm
|
from .forms import PolymorphicModelChoiceForm
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Django 2.0+
|
||||||
|
from django.urls import URLResolver
|
||||||
|
except ImportError:
|
||||||
|
# Django < 2.0
|
||||||
|
from django.urls import RegexURLResolver as URLResolver
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
long = int
|
long = int
|
||||||
|
|
||||||
@@ -265,7 +271,7 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
|||||||
ct_id = self.model.objects.values_list('polymorphic_ctype_id', flat=True).get(pk=object_id)
|
ct_id = self.model.objects.values_list('polymorphic_ctype_id', flat=True).get(pk=object_id)
|
||||||
|
|
||||||
real_admin = self._get_real_admin_by_ct(ct_id)
|
real_admin = self._get_real_admin_by_ct(ct_id)
|
||||||
resolver = RegexURLResolver('^', real_admin.urls)
|
resolver = URLResolver('^', real_admin.urls)
|
||||||
resolvermatch = resolver.resolve(path) # May raise Resolver404
|
resolvermatch = resolver.resolve(path) # May raise Resolver404
|
||||||
if not resolvermatch:
|
if not resolvermatch:
|
||||||
raise Http404("No match for path '{0}' in admin subclass.".format(path))
|
raise Http404("No match for path '{0}' in admin subclass.".format(path))
|
||||||
|
|||||||
Reference in New Issue
Block a user