django-smartbase-admin 1.0.21__py3-none-any.whl → 1.0.22__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ from django.contrib.admin.widgets import (
12
12
  from django.contrib.auth.forms import ReadOnlyPasswordHashWidget
13
13
  from django.core.exceptions import ValidationError
14
14
  from django.template.loader import render_to_string
15
- from django.urls import reverse, NoReverseMatch
15
+ from django.urls import reverse
16
16
  from django.utils.formats import get_format
17
17
  from django.utils.http import urlencode
18
18
  from django.utils.safestring import mark_safe
@@ -22,6 +22,7 @@ from filer.fields.file import AdminFileWidget as FilerAdminFileWidget
22
22
  from filer.fields.image import AdminImageWidget
23
23
  from filer.models import File
24
24
 
25
+ from django_smartbase_admin.admin.site import sb_admin_site
25
26
  from django_smartbase_admin.engine.admin_base_view import (
26
27
  SBADMIN_PARENT_INSTANCE_PK_VAR,
27
28
  SBADMIN_PARENT_INSTANCE_LABEL_VAR,
@@ -36,6 +37,12 @@ from django_smartbase_admin.templatetags.sb_admin_tags import (
36
37
  )
37
38
  from django_smartbase_admin.utils import is_modal
38
39
 
40
+ try:
41
+ # Django >= 5.0
42
+ from django.contrib.admin.exceptions import NotRegistered
43
+ except ImportError:
44
+ from django.contrib.admin.sites import NotRegistered
45
+
39
46
  logger = logging.getLogger(__name__)
40
47
 
41
48
 
@@ -438,21 +445,25 @@ class SBAdminAutocompleteWidget(
438
445
  return context
439
446
 
440
447
  def add_related_buttons_urls(self, parsed_value, request, context):
441
- related_model = self.model
442
- app_label = related_model._meta.app_label
443
- model_name = related_model._meta.model_name
444
-
445
448
  try:
446
- if parsed_value and self.has_view_or_change_permission(request, self.model):
447
- change_url = reverse(
448
- "sb_admin:{}_{}_change".format(app_label, model_name),
449
- args=(parsed_value,),
449
+ if hasattr(sb_admin_site, "get_model_admin"):
450
+ # Django >= 5.0
451
+ related_model_admin = sb_admin_site.get_model_admin(self.model)
452
+ else:
453
+ related_model_admin = sb_admin_site._registry.get(self.model)
454
+ if not related_model_admin:
455
+ return
456
+ if parsed_value and related_model_admin.has_view_or_change_permission(
457
+ request, self.model
458
+ ):
459
+ context["widget"]["attrs"]["related_edit_url"] = (
460
+ related_model_admin.get_detail_url(parsed_value)
461
+ )
462
+ if related_model_admin.has_add_permission(request, self.model):
463
+ context["widget"]["attrs"]["related_add_url"] = (
464
+ related_model_admin.get_new_url(request)
450
465
  )
451
- context["widget"]["attrs"]["related_edit_url"] = change_url
452
- if self.has_add_permission(request, self.model):
453
- add_url = reverse("sb_admin:{}_{}_add".format(app_label, model_name))
454
- context["widget"]["attrs"]["related_add_url"] = add_url
455
- except NoReverseMatch:
466
+ except NotRegistered:
456
467
  pass
457
468
 
458
469
  def is_multiselect(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-smartbase-admin
3
- Version: 1.0.21
3
+ Version: 1.0.22
4
4
  Summary:
5
5
  Home-page: https://smartbase-sk.github.io/django-smartbase-admin-docs/
6
6
  License: MIT
@@ -5,7 +5,7 @@ django_smartbase_admin/actions/advanced_filters.py,sha256=Vm8b6TAwNehR8INjolFG7p
5
5
  django_smartbase_admin/admin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  django_smartbase_admin/admin/admin_base.py,sha256=lU73GWjWvrPTsIXgmLaR88ie_K71J4NsU7qUqSzDrqg,47274
7
7
  django_smartbase_admin/admin/site.py,sha256=sJiVX2ljUgNN6MnlLfsTyJs7Dl52iC2rtLwkg962ydM,6841
8
- django_smartbase_admin/admin/widgets.py,sha256=3ms7rI4uHtW6cNcJu94S2e9q4eVONi2ticAYyQdeP2I,25881
8
+ django_smartbase_admin/admin/widgets.py,sha256=7w2kYK-1EAUb7ZCOi10EqAZPZYaCWUhCcji-062OdPo,26240
9
9
  django_smartbase_admin/apps.py,sha256=heZq5O2GHlkJdhUCHbRR7Nmm0irSxnL9NMqY43_O7V4,599
10
10
  django_smartbase_admin/compilemessages.py,sha256=-_FEFQlOvE4L8UzSuUxSxZQjgGlwL9IZtmg59fW_kIQ,342
11
11
  django_smartbase_admin/engine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -716,7 +716,7 @@ django_smartbase_admin/views/global_filter_view.py,sha256=eYo1moJGyi7jc2cPDA5ZBi
716
716
  django_smartbase_admin/views/media_view.py,sha256=5BLWXuzynF7nM34t-mf2BQSRN5ojY8HxpLIqt7Jiq9g,292
717
717
  django_smartbase_admin/views/translations_view.py,sha256=hktmkJIZ0EJxgnzjHLIoRDY0ckFa5wkbaoFZg32UWYw,20441
718
718
  django_smartbase_admin/views/user_config_view.py,sha256=7GcC8iw_GRn23AWehltJpVmSMW3Cq6WFxSuXeYiFylg,1124
719
- django_smartbase_admin-1.0.21.dist-info/LICENSE.md,sha256=okRGMBOYvyhprt2eTpX_QXqpzC0MODF-U7zX-4fKPjQ,1078
720
- django_smartbase_admin-1.0.21.dist-info/METADATA,sha256=cvjBtOq-qHXQpttOCcaZHIZ7BSk3IsQeUUQBsrJwSuU,5375
721
- django_smartbase_admin-1.0.21.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
722
- django_smartbase_admin-1.0.21.dist-info/RECORD,,
719
+ django_smartbase_admin-1.0.22.dist-info/LICENSE.md,sha256=okRGMBOYvyhprt2eTpX_QXqpzC0MODF-U7zX-4fKPjQ,1078
720
+ django_smartbase_admin-1.0.22.dist-info/METADATA,sha256=bRXtkqqRMYPwtZSyZqm997liG7BlVhsXEBWhp3NJZic,5375
721
+ django_smartbase_admin-1.0.22.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
722
+ django_smartbase_admin-1.0.22.dist-info/RECORD,,