From cfcf6b1a46b1c9b183971f5d44681e0dc6765b3d Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Tue, 18 Nov 2014 17:04:20 +0200 Subject: [PATCH 1/2] Make inlines to work corectly with non sortable inlines --- .../adminsortable/js/admin.sortable.stacked.inlines.js | 10 +++++++--- .../adminsortable/js/admin.sortable.tabular.inlines.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/adminsortable/static/adminsortable/js/admin.sortable.stacked.inlines.js b/adminsortable/static/adminsortable/js/admin.sortable.stacked.inlines.js index 2afcb5f..5a1f8d4 100644 --- a/adminsortable/static/adminsortable/js/admin.sortable.stacked.inlines.js +++ b/adminsortable/static/adminsortable/js/admin.sortable.stacked.inlines.js @@ -1,12 +1,16 @@ (function($){ $(function() { - if ($(':hidden[name="admin_sorting_url"]').length > 0) + var sorting_urls = $(':hidden[name="admin_sorting_url"]'); + if (sorting_urls.length > 0) { - var sortable_inline_rows = $('.inline-group .inline-related'); + var sortable_inline_groups = sorting_urls.closest('.inline-group') + var sortable_inline_rows = sortable_inline_groups.find('.inline-related'); + + sortable_inline_groups.addClass('sortable') sortable_inline_rows.addClass('sortable'); - $('.inline-group').sortable({ + sortable_inline_groups.sortable({ axis : 'y', containment : 'parent', create: function(event, ui) { diff --git a/adminsortable/static/adminsortable/js/admin.sortable.tabular.inlines.js b/adminsortable/static/adminsortable/js/admin.sortable.tabular.inlines.js index e8c39c5..44c9fe8 100644 --- a/adminsortable/static/adminsortable/js/admin.sortable.tabular.inlines.js +++ b/adminsortable/static/adminsortable/js/admin.sortable.tabular.inlines.js @@ -1,11 +1,15 @@ (function($){ $(function() { - if ($(':hidden[name="admin_sorting_url"]').length > 0) + var sorting_urls = $(':hidden[name="admin_sorting_url"]'); + if (sorting_urls.length) { - var tabular_inline_rows = $('.tabular table tbody tr'); + var sortable_inline_group = sorting_urls.closest('.inline-group') + var tabular_inline_rows = sortable_inline_group.find('.tabular table tbody tr'); + tabular_inline_rows.addClass('sortable'); - $('.tabular.inline-related').sortable({ + + sortable_inline_group.find('.tabular.inline-related').sortable({ axis : 'y', containment : 'parent', create: function(event, ui) { From cbce6debb4e4be7b67226c0d8c066d93ffb14d6b Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Tue, 18 Nov 2014 17:04:58 +0200 Subject: [PATCH 2/2] Update sample_project for easy testing sortable and nonsortable inlines --- sample_project/app/admin.py | 17 +++++++++++++++-- sample_project/app/models.py | 20 ++++++++++++++++++++ sample_project/database/test_project.sqlite | Bin 94208 -> 99328 bytes 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/sample_project/app/admin.py b/sample_project/app/admin.py index c79aaf4..3fca3f2 100644 --- a/sample_project/app/admin.py +++ b/sample_project/app/admin.py @@ -6,7 +6,7 @@ from adminsortable.admin import (SortableAdmin, SortableTabularInline, from adminsortable.utils import get_is_sortable from app.models import (Category, Widget, Project, Credit, Note, GenericNote, Component, Person, NonSortableCategory, SortableCategoryWidget, - SortableNonInlineCategory) + SortableNonInlineCategory, NonSortableCredit, NonSortableNote) admin.site.register(Category, SortableAdmin) @@ -56,8 +56,21 @@ class GenericNoteInline(SortableGenericStackedInline): extra = 0 +class NonSortableCreditInline(admin.TabularInline): + model = NonSortableCredit + extra = 1 + + +class NonSortableNoteInline(admin.StackedInline): + model = NonSortableNote + extra = 0 + + class ProjectAdmin(SortableAdmin): - inlines = [CreditInline, NoteInline, GenericNoteInline] + inlines = [ + CreditInline, NoteInline, GenericNoteInline, + NonSortableCreditInline, NonSortableNoteInline + ] list_display = ['__unicode__', 'category'] admin.site.register(Project, ProjectAdmin) diff --git a/sample_project/app/models.py b/sample_project/app/models.py index e90e85e..d882930 100644 --- a/sample_project/app/models.py +++ b/sample_project/app/models.py @@ -71,6 +71,25 @@ class Note(Sortable): return self.text +# Registered as a tabular inline on `Project` which can't be sorted +class NonSortableCredit(models.Model): + project = models.ForeignKey(Project) + first_name = models.CharField(max_length=30) + last_name = models.CharField(max_length=30) + + def __unicode__(self): + return '{0} {1}'.format(self.first_name, self.last_name) + + +# Registered as a stacked inline on `Project` which can't be sorted +class NonSortableNote(models.Model): + project = models.ForeignKey(Project) + text = models.CharField(max_length=100) + + def __unicode__(self): + return self.text + + # A generic bound model class GenericNote(SimpleModel, Sortable): content_type = models.ForeignKey(ContentType, @@ -97,6 +116,7 @@ class Component(SimpleModel, Sortable): return self.title + class Person(Sortable): class Meta(Sortable.Meta): verbose_name_plural = 'People' diff --git a/sample_project/database/test_project.sqlite b/sample_project/database/test_project.sqlite index 723eb7491600da6e3ed70d6939223506a4eb67b8..6bbcbecf4762523e9f5034fa08cb53c376b69135 100644 GIT binary patch delta 1810 zcmaJ>ZD?Cn7{1SY&Rt5Iv1G|@>}u<69CW4IYL~{e`Dpr;VWw1Di&S(=)8;a(BWct8 zP*BrWM43Nay>(ZIe-t-{ir|8aLw}ax1c!woh&Wdq{?H$8e-%H@&CN!eq+XK4<$2!s zd7tyX=iJ2`^5W||PBlA!lO!oA{&$`uEBk!{Jn$>Y0SuHi2+ZtJFFIP-zVoK0Wrt`w#C$w}ftt;3;IWjJI(fMO?v; zxJ~tRKl$khB`8gc^cJ0^FKL}_(x1%1yeuI0bd=4rSJ^5%$G%`!neJR%)m1)P43JQ0 zR5&_Om(osXIV~}h%xT9n*%$6H`gh<~xL!+{@7ir7T`Cs;CjSp*ZB=XoDk}N+ssB>_R4e z(8bXX$ILUy^l`0>by-+h$BKKPg(C!~NHji^;YPP{Sw>rf$}tFMDbiS%q15|I$Zj(( zKL8JUj42s=jj)UkF(Ax*EQMxi*?|=c3EnZ#P26uq6Wh;fHfm>AL@#44q~2+*QQa( z?-ZljB?Tn5#+KOt{X-YUap=Hx=;FwLhhtM2p8Wi!ueGr7cU%GAE7O3 delta 609 zcmXw$T}YE*6vvajdxD-i-v<_3_n7hsTsAUjgkV3E(#)jaW7M{ZOvU|MMz&t z-8f$83A%`&x+pQ~1$UKT3_&jnVh|C8K`iQ~y6UE)cUcdd1Lt@C2hRCF)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