Skip to content

Commit

Permalink
Merge pull request #147 from gagandeep/master
Browse files Browse the repository at this point in the history
Fix for Django 2.1 breaking Admin tree editor
  • Loading branch information
coordt authored Dec 21, 2018
2 parents 58ec14f + d542684 commit 3765851
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 12 additions & 2 deletions categories/editor/tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ def old_changelist_view(self, request, extra_context=None):
self.list_display_links, self.list_filter, self.date_hierarchy,
self.search_fields, self.list_select_related,
self.list_per_page, self.list_editable, self)
else:
elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1):
params = (
request, self.model, list_display,
self.list_display_links, self.list_filter, self.date_hierarchy,
self.search_fields, self.list_select_related,
self.list_per_page, self.list_max_show_all,
self.list_editable, self)
else:
params = (
request, self.model, list_display,
self.list_display_links, self.list_filter, self.date_hierarchy,
self.search_fields, self.list_select_related,
self.list_per_page, self.list_max_show_all,
self.list_editable, self, self.sortable_by)
cl = TreeChangeList(*params)
except IncorrectLookupParameters:
# Wacky lookup parameters were given, so redirect to the main
Expand Down Expand Up @@ -243,14 +250,17 @@ def old_changelist_view(self, request, extra_context=None):
}
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
context['root_path'] = self.admin_site.root_path
else:
elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1):
selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count)

context.update({
'module_name': force_text(opts.verbose_name_plural),
'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
'selection_note_all': selection_note_all % {'total_count': cl.result_count},
})
else:
context['opts'] = self.model._meta

context.update(extra_context or {})
return render_to_response(self.change_list_template or [
'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
Expand Down
4 changes: 2 additions & 2 deletions categories/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, **kwargs):

try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^categories\.fields\.CategoryFKField"])
add_introspection_rules([], ["^categories\.fields\.CategoryM2MField"])
add_introspection_rules([], [r"^categories\.fields\.CategoryFKField"])
add_introspection_rules([], [r"^categories\.fields\.CategoryM2MField"])
except ImportError:
pass
11 changes: 6 additions & 5 deletions example/simpletext/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class Meta:
def __unicode__(self):
return self.name

# If using the get_absolute_url method, put the following line at the top of this file:
from django.db.models import permalink

@permalink
def get_absolute_url(self):
return ('simpletext_detail_view_name', [str(self.id)])
try:
from django.db.models import permalink
return permalink('simpletext_detail_view_name', [str(self.id)])
except ImportError:
from django.urls import reverse
return reverse('simpletext_detail_view_name', args=[str(self.id)])


class SimpleCategory(CategoryBase):
Expand Down

0 comments on commit 3765851

Please sign in to comment.