Skip to content

Commit

Permalink
Django 1.8 compatible ModelAdmin.get_urls
Browse files Browse the repository at this point in the history
This replaces code that was removed in bb3a835.

Closes #26.
  • Loading branch information
David Krisch committed Nov 17, 2016
1 parent bdd8014 commit ace1ba9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions modelclone/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 4 additions & 1 deletion tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ace1ba9

Please sign in to comment.