Fix Sorting by ForeignKey
Removed do_inline_sorting_url and get_object_or_404 check in admin. The model_type_id should *always* be passed in. Removed test that asserted that Categories weren't sortable as part of the Project admin. Categories *should* be sortable as part of Project admin as they are a Sortable ForeignKey. Fixed object_rep template to pass in model_type_id again. Updated README. Version bump to 2.0.21
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
VERSION = (2, 0, 20)
|
||||
VERSION = (2, 0, 21)
|
||||
DEV_N = None
|
||||
|
||||
|
||||
|
||||
+3
-18
@@ -106,16 +106,10 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
||||
info = opts.app_label, opts.model_name
|
||||
except AttributeError:
|
||||
# Django < 1.7
|
||||
info = opts.app_label, opts.modul_name
|
||||
info = opts.app_label, opts.model_name
|
||||
|
||||
# this ajax view changes the order of instances of self.model
|
||||
# this ajax view changes the order of instances of the model type
|
||||
admin_do_sorting_url = url(
|
||||
r'^sort/do-sorting/$',
|
||||
self.admin_site.admin_view(self.do_sorting_view),
|
||||
name='%s_%s_do_sorting' % info)
|
||||
|
||||
# this ajax view changes the order of instances of inline models
|
||||
admin_do_inline_sorting_url = url(
|
||||
r'^sort/do-sorting/(?P<model_type_id>\d+)/$',
|
||||
self.admin_site.admin_view(self.do_sorting_view),
|
||||
name='%s_%s_do_sorting' % info)
|
||||
@@ -127,7 +121,6 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
||||
name='%s_%s_sort' % info)
|
||||
|
||||
urls = [
|
||||
admin_do_inline_sorting_url,
|
||||
admin_do_sorting_url,
|
||||
admin_sort_url
|
||||
] + urls
|
||||
@@ -280,15 +273,7 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
||||
|
||||
if request.is_ajax():
|
||||
try:
|
||||
if model_type_id is None:
|
||||
klass = self.model
|
||||
else:
|
||||
klass = get_object_or_404(ContentType,
|
||||
id=model_type_id).model_class()
|
||||
if klass not in (inline.model for inline in self.inlines):
|
||||
raise Http404(
|
||||
'There is no inline model with type id: {0}'.format(
|
||||
model_type_id))
|
||||
klass = ContentType.objects.get(id=model_type_id).model_class()
|
||||
|
||||
indexes = list(map(str,
|
||||
request.POST.get('indexes', []).split(',')))
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
<form>
|
||||
<input name="pk" type="hidden" value="{{ object.pk }}" />
|
||||
<a href="{% url opts|admin_urlname:'do_sorting' %}" class="admin_sorting_url"><i class="fa fa-{% if forloop.first %}sort-desc{% elif forloop.last %}sort-asc{% else %}sort{% endif %}"></i> {{ object }}</a>
|
||||
<a href="{% url opts|admin_urlname:'do_sorting' object.model_type_id %}" class="admin_sorting_url"><i class="fa fa-{% if forloop.first %}sort-desc{% elif forloop.last %}sort-asc{% else %}sort{% endif %}"></i> {{ object }}</a>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user