2013-03-11 00:53:05 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
|
|
|
|
|
|
from adminsortable.admin import (SortableAdmin, SortableTabularInline,
|
2014-09-21 19:14:03 +00:00
|
|
|
SortableStackedInline, SortableGenericStackedInline,
|
|
|
|
|
NonSortableParentAdmin)
|
2013-04-28 02:58:02 +00:00
|
|
|
from adminsortable.utils import get_is_sortable
|
2017-12-05 02:29:55 +00:00
|
|
|
from .models import (Category, Widget, Project, Credit, Note, GenericNote,
|
2014-10-25 00:34:06 +00:00
|
|
|
Component, Person, NonSortableCategory, SortableCategoryWidget,
|
2015-08-24 12:04:05 +00:00
|
|
|
SortableNonInlineCategory, NonSortableCredit, NonSortableNote,
|
2015-08-24 16:55:56 +00:00
|
|
|
CustomWidget, CustomWidgetComponent, BackwardCompatibleWidget)
|
2013-03-11 00:53:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Category, SortableAdmin)
|
|
|
|
|
|
|
|
|
|
|
2013-04-28 02:58:02 +00:00
|
|
|
class ComponentInline(SortableStackedInline):
|
2015-11-18 14:20:45 +00:00
|
|
|
# fieldsets = (
|
|
|
|
|
# ('foo', {
|
|
|
|
|
# 'classes': ('collapse',),
|
|
|
|
|
# 'fields': ('title',)
|
|
|
|
|
# }),
|
|
|
|
|
# ('', {
|
|
|
|
|
# 'classes': ('collapse',),
|
|
|
|
|
# 'fields': ('widget',)
|
|
|
|
|
# }),
|
|
|
|
|
# )
|
2013-04-28 02:58:02 +00:00
|
|
|
model = Component
|
|
|
|
|
|
2017-03-16 13:44:51 +00:00
|
|
|
def get_queryset(self, request):
|
|
|
|
|
qs = super(ComponentInline, self).get_queryset(
|
2013-05-03 12:35:17 +00:00
|
|
|
request).exclude(title__icontains='2')
|
2013-04-28 02:58:02 +00:00
|
|
|
if get_is_sortable(qs):
|
|
|
|
|
self.model.is_sortable = True
|
|
|
|
|
else:
|
|
|
|
|
self.model.is_sortable = False
|
|
|
|
|
return qs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WidgetAdmin(SortableAdmin):
|
2017-03-16 13:44:51 +00:00
|
|
|
def get_queryset(self, request):
|
2013-04-28 02:58:02 +00:00
|
|
|
"""
|
|
|
|
|
A simple example demonstrating that adminsortable works even in
|
|
|
|
|
situations where you need to filter the queryset in admin. Here,
|
|
|
|
|
we are just filtering out `widget` instances with an pk higher
|
|
|
|
|
than 3
|
|
|
|
|
"""
|
2017-03-16 13:44:51 +00:00
|
|
|
qs = super(WidgetAdmin, self).get_queryset(request)
|
2013-04-28 02:58:02 +00:00
|
|
|
return qs.filter(id__lte=3)
|
|
|
|
|
|
|
|
|
|
inlines = [ComponentInline]
|
|
|
|
|
|
|
|
|
|
admin.site.register(Widget, WidgetAdmin)
|
|
|
|
|
|
|
|
|
|
|
2019-02-21 14:56:08 +00:00
|
|
|
class CreditAdmin(SortableAdmin):
|
|
|
|
|
raw_id_fields = ('project',)
|
|
|
|
|
|
|
|
|
|
admin.site.register(Credit, CreditAdmin)
|
|
|
|
|
|
|
|
|
|
|
2013-03-11 00:53:05 +00:00
|
|
|
class CreditInline(SortableTabularInline):
|
|
|
|
|
model = Credit
|
2014-09-07 00:36:51 +00:00
|
|
|
extra = 1
|
2013-03-11 00:53:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class NoteInline(SortableStackedInline):
|
|
|
|
|
model = Note
|
2015-12-23 21:39:45 +00:00
|
|
|
extra = 2
|
2013-03-11 00:53:05 +00:00
|
|
|
|
2018-07-09 11:49:55 +00:00
|
|
|
def after_sorting(self):
|
|
|
|
|
print('I happened after sorting')
|
|
|
|
|
|
2013-03-11 00:53:05 +00:00
|
|
|
|
2013-03-15 09:10:01 +00:00
|
|
|
class GenericNoteInline(SortableGenericStackedInline):
|
|
|
|
|
model = GenericNote
|
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
2014-11-18 15:04:58 +00:00
|
|
|
class NonSortableCreditInline(admin.TabularInline):
|
|
|
|
|
model = NonSortableCredit
|
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NonSortableNoteInline(admin.StackedInline):
|
|
|
|
|
model = NonSortableNote
|
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
2013-03-11 00:53:05 +00:00
|
|
|
class ProjectAdmin(SortableAdmin):
|
2014-11-18 15:04:58 +00:00
|
|
|
inlines = [
|
|
|
|
|
CreditInline, NoteInline, GenericNoteInline,
|
|
|
|
|
NonSortableCreditInline, NonSortableNoteInline
|
|
|
|
|
]
|
2019-02-11 15:15:39 +00:00
|
|
|
list_display = ['__str__', 'category', 'isApproved',]
|
|
|
|
|
list_filter = ('category__title', 'isApproved',)
|
2018-06-18 15:40:24 +00:00
|
|
|
after_sorting_js_callback_name = 'afterSortCallback'
|
2018-10-05 14:53:56 +00:00
|
|
|
search_fields = ['title']
|
2018-06-18 15:40:24 +00:00
|
|
|
sortable_change_list_template = 'adminsortable/custom_change_list.html'
|
2018-07-09 11:49:55 +00:00
|
|
|
sortable_change_form_template = 'adminsortable/custom_change_form.html'
|
|
|
|
|
|
|
|
|
|
def after_sorting(self):
|
|
|
|
|
print('I happened after sorting')
|
2013-03-11 00:53:05 +00:00
|
|
|
|
|
|
|
|
admin.site.register(Project, ProjectAdmin)
|
2014-02-05 14:36:03 +00:00
|
|
|
|
|
|
|
|
|
2014-02-05 16:06:15 +00:00
|
|
|
class PersonAdmin(SortableAdmin):
|
2014-12-22 15:25:35 +00:00
|
|
|
list_display = ['__str__', 'is_board_member']
|
2014-02-05 16:06:15 +00:00
|
|
|
|
|
|
|
|
admin.site.register(Person, PersonAdmin)
|
2014-09-21 19:14:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class SortableCategoryWidgetInline(SortableStackedInline):
|
|
|
|
|
model = SortableCategoryWidget
|
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NonSortableCategoryAdmin(NonSortableParentAdmin):
|
|
|
|
|
inlines = [SortableCategoryWidgetInline]
|
|
|
|
|
|
|
|
|
|
admin.site.register(NonSortableCategory, NonSortableCategoryAdmin)
|
2014-10-25 00:34:06 +00:00
|
|
|
|
|
|
|
|
|
2015-08-24 12:04:05 +00:00
|
|
|
class CustomWidgetComponentInline(SortableStackedInline):
|
|
|
|
|
model = CustomWidgetComponent
|
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomWidgetAdmin(SortableAdmin):
|
|
|
|
|
inlines = [CustomWidgetComponentInline]
|
|
|
|
|
|
|
|
|
|
|
2014-10-25 00:34:06 +00:00
|
|
|
admin.site.register(SortableNonInlineCategory, SortableAdmin)
|
2015-08-24 12:04:05 +00:00
|
|
|
admin.site.register(CustomWidget, CustomWidgetAdmin)
|
2015-08-24 16:55:56 +00:00
|
|
|
admin.site.register(BackwardCompatibleWidget, SortableAdmin)
|