From 0daba7c163df8a700d3fa33cfbc1c9f8a479221b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Bezugl=C3=B5i?= Date: Wed, 24 Oct 2018 22:39:51 +0300 Subject: [PATCH 1/4] Fix django 2.0 compatibility --- .gitignore | 1 + genericadmin/admin.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5301ecd..407c264 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ MANIFEST *egg* *.bak *.tmproj +.idea \ No newline at end of file diff --git a/genericadmin/admin.py b/genericadmin/admin.py index 40aff4c..450d1d2 100755 --- a/genericadmin/admin.py +++ b/genericadmin/admin.py @@ -23,6 +23,7 @@ except ImportError: from django.contrib.admin.options import IS_POPUP_VAR from django.core.exceptions import ObjectDoesNotExist +from django.views.generic import RedirectView JS_PATH = getattr(settings, 'GENERICADMIN_JS', 'genericadmin/js/') @@ -63,7 +64,12 @@ def get_generic_field_list(self, request, prefix=''): fields['prefix'] = prefix field_list.append(fields) else: - for field in self.model._meta.virtual_fields: + # virtual_fields were deprecated in django 2.0 + try: + fields = self.model._meta.virtual_fields + except AttributeError: + fields = self.model._meta.private_fields + for field in fields: if isinstance(field, GenericForeignKey) and \ field.ct_field not in exclude and field.fk_field not in exclude: field_list.append({ @@ -90,6 +96,10 @@ def wrapper(*args, **kwargs): custom_urls = [ url(r'^obj-data/$', wrap(self.generic_lookup), name='admin_genericadmin_obj_lookup'), url(r'^genericadmin-init/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init'), + + # to work with django 2.0 + url(r'../genericadmin-init/change/$', + wrap(RedirectView.as_view(pattern_name='%s:admin_genericadmin_init' % self.admin_site.name))), ] return custom_urls + super(BaseGenericModelAdmin, self).get_urls() From 98846bdda8c22d61cd1558984ec2d9883751ec53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Bezugl=C3=B5i?= Date: Wed, 24 Oct 2018 22:49:33 +0300 Subject: [PATCH 2/4] Fix django 2.0 compatibility --- genericadmin/admin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/genericadmin/admin.py b/genericadmin/admin.py index 450d1d2..c92239d 100755 --- a/genericadmin/admin.py +++ b/genericadmin/admin.py @@ -80,10 +80,16 @@ def get_generic_field_list(self, request, prefix=''): }) if hasattr(self, 'inlines') and len(self.inlines) > 0: - for FormSet, inline in zip(self.get_formsets_with_inlines(request), self.get_inline_instances(request)): - if hasattr(inline, 'get_generic_field_list'): - prefix = FormSet.get_default_prefix() - field_list = field_list + inline.get_generic_field_list(request, prefix) + try: + for FormSet, inline in zip(self.get_formsets_with_inlines(request), self.get_inline_instances(request)): + if hasattr(inline, 'get_generic_field_list'): + prefix = FormSet.get_default_prefix() + field_list = field_list + inline.get_generic_field_list(request, prefix) + except AttributeError: + for FormSet, inline in self.get_formsets_with_inlines(request): + if hasattr(inline, 'get_generic_field_list'): + prefix = FormSet.get_default_prefix() + field_list = field_list + inline.get_generic_field_list(request, prefix) return field_list From 0843b79c2cb436d32d86e8caa923520405c020ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Bezugl=C3=B5i?= Date: Wed, 24 Oct 2018 22:50:37 +0300 Subject: [PATCH 3/4] bump version 0.7.0 -> 0.7.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index faf0c0f..e4395a3 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def convert_readme(): setup( name='django-genericadmin', - version='0.7.0', + version='0.7.1', description="Adds support for generic relations within Django's admin interface.", author='Weston Nielson, Jan Schrewe, Arthur Hanson', author_email='wnielson@gmail.com, jschrewe@googlemail.com, worldnomad@gmail.com', From e7f11ed85b9814c01e5315d0867229610fd62a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Bezugl=C3=B5i?= Date: Wed, 24 Oct 2018 23:06:45 +0300 Subject: [PATCH 4/4] Fix django 2.0 compatibility --- genericadmin/admin.py | 4 ++-- genericadmin/static/genericadmin/js/genericadmin.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/genericadmin/admin.py b/genericadmin/admin.py index c92239d..afa9aa9 100755 --- a/genericadmin/admin.py +++ b/genericadmin/admin.py @@ -104,8 +104,8 @@ def wrapper(*args, **kwargs): url(r'^genericadmin-init/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init'), # to work with django 2.0 - url(r'../genericadmin-init/change/$', - wrap(RedirectView.as_view(pattern_name='%s:admin_genericadmin_init' % self.admin_site.name))), + url(r'^../obj-data/$', wrap(self.generic_lookup), name='admin_genericadmin_obj_lookup_change'), + url(r'^../genericadmin-init/change/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init'), ] return custom_urls + super(BaseGenericModelAdmin, self).get_urls() diff --git a/genericadmin/static/genericadmin/js/genericadmin.js b/genericadmin/static/genericadmin/js/genericadmin.js index 529dbb9..072251a 100755 --- a/genericadmin/static/genericadmin/js/genericadmin.js +++ b/genericadmin/static/genericadmin/js/genericadmin.js @@ -73,7 +73,13 @@ }, getLookupUrl: function(cID) { - return '../../../' + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID); + var forword = '../../../'; + var suffix = '/change/'; + var href = window.location.href; + if (href.indexOf(suffix, href.length - suffix.length) !== -1) { + forword += '../'; + } + return forword + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID); }, getFkId: function() {