Added `after_sorting` method to SortableAdminBase class that can be defined on a model admin to be executed after sorting has occurred.
parent
3f49a72a6d
commit
6d5f9e97b4
|
|
@ -56,6 +56,11 @@ class SortableAdminBase(object):
|
|||
return super(SortableAdminBase, self).changelist_view(request,
|
||||
extra_context=extra_context)
|
||||
|
||||
# override this function in your SortableAdmin if you need to do something
|
||||
# after sorting has occurred
|
||||
def after_sorting(self):
|
||||
pass
|
||||
|
||||
|
||||
class SortableAdmin(SortableAdminBase, ModelAdmin):
|
||||
"""
|
||||
|
|
@ -303,6 +308,8 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
|||
AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
self.after_sorting()
|
||||
|
||||
return HttpResponse(json.dumps(response, ensure_ascii=False),
|
||||
content_type='application/json')
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ class NoteInline(SortableStackedInline):
|
|||
model = Note
|
||||
extra = 2
|
||||
|
||||
def after_sorting(self):
|
||||
print('I happened after sorting')
|
||||
|
||||
|
||||
class GenericNoteInline(SortableGenericStackedInline):
|
||||
model = GenericNote
|
||||
|
|
@ -83,9 +86,13 @@ class ProjectAdmin(SortableAdmin):
|
|||
NonSortableCreditInline, NonSortableNoteInline
|
||||
]
|
||||
list_display = ['__str__', 'category']
|
||||
list_filter = ('category__title',)
|
||||
after_sorting_js_callback_name = 'afterSortCallback'
|
||||
sortable_change_list_template = 'adminsortable/custom_change_list.html'
|
||||
sortable_change_form_template = "adminsortable/custom_change_form.html"
|
||||
sortable_change_form_template = 'adminsortable/custom_change_form.html'
|
||||
|
||||
def after_sorting(self):
|
||||
print('I happened after sorting')
|
||||
|
||||
admin.site.register(Project, ProjectAdmin)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue