From ace1ba9a6fd5df43ad9aed3835df5f4b45fc595e Mon Sep 17 00:00:00 2001 From: David Krisch Date: Thu, 17 Nov 2016 11:18:41 -1000 Subject: [PATCH] Django 1.8 compatible ModelAdmin.get_urls This replaces code that was removed in bb3a835. Closes #26. --- modelclone/admin.py | 18 +++++++++++++----- tests/test_admin.py | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modelclone/admin.py b/modelclone/admin.py index 3bc8ac1..95d0d25 100644 --- a/modelclone/admin.py +++ b/modelclone/admin.py @@ -46,11 +46,19 @@ def get_urls(self): self.model._meta.app_label, getattr(self.model._meta, 'module_name', getattr(self.model._meta, 'model_name', ''))) - new_urlpatterns = [ - url(r'^(.+)/change/clone/$', - self.admin_site.admin_view(self.clone_view), - name=url_name) - ] + if VERSION[1] < 9: + from django.conf.urls import patterns + new_urlpatterns = patterns('', + url(r'^(.+)/clone/$', + self.admin_site.admin_view(self.clone_view), + name=url_name) + ) + else: + new_urlpatterns = [ + url(r'^(.+)/change/clone/$', + self.admin_site.admin_view(self.clone_view), + name=url_name) + ] original_urlpatterns = super(ClonableModelAdmin, self).get_urls() diff --git a/tests/test_admin.py b/tests/test_admin.py index d280dda..212fe8c 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -85,7 +85,10 @@ def test_clone_view_is_wrapped_as_admin_view(self): def test_clone_view_url_name(self): post_id = self.post.id - expected_url = '/admin/posts/post/{0}/change/clone/'.format(post_id) + if django.VERSION[1] < 9: + expected_url = '/admin/posts/post/{0}/clone/'.format(post_id) + else: + expected_url = '/admin/posts/post/{0}/change/clone/'.format(post_id) assert reverse('admin:posts_post_clone', args=(post_id,)) == expected_url