Merge pull request #96 from MagicSolutions/fix_js_for_inlines
Make inlines to work corectly with non sortable inlinesmaster
commit
81fc032c8b
|
|
@ -1,12 +1,16 @@
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
$(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');
|
sortable_inline_rows.addClass('sortable');
|
||||||
|
|
||||||
$('.inline-group').sortable({
|
sortable_inline_groups.sortable({
|
||||||
axis : 'y',
|
axis : 'y',
|
||||||
containment : 'parent',
|
containment : 'parent',
|
||||||
create: function(event, ui) {
|
create: function(event, ui) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
$(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_rows.addClass('sortable');
|
||||||
$('.tabular.inline-related').sortable({
|
|
||||||
|
sortable_inline_group.find('.tabular.inline-related').sortable({
|
||||||
axis : 'y',
|
axis : 'y',
|
||||||
containment : 'parent',
|
containment : 'parent',
|
||||||
create: function(event, ui) {
|
create: function(event, ui) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from adminsortable.admin import (SortableAdmin, SortableTabularInline,
|
||||||
from adminsortable.utils import get_is_sortable
|
from adminsortable.utils import get_is_sortable
|
||||||
from app.models import (Category, Widget, Project, Credit, Note, GenericNote,
|
from app.models import (Category, Widget, Project, Credit, Note, GenericNote,
|
||||||
Component, Person, NonSortableCategory, SortableCategoryWidget,
|
Component, Person, NonSortableCategory, SortableCategoryWidget,
|
||||||
SortableNonInlineCategory)
|
SortableNonInlineCategory, NonSortableCredit, NonSortableNote)
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Category, SortableAdmin)
|
admin.site.register(Category, SortableAdmin)
|
||||||
|
|
@ -56,8 +56,21 @@ class GenericNoteInline(SortableGenericStackedInline):
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
|
class NonSortableCreditInline(admin.TabularInline):
|
||||||
|
model = NonSortableCredit
|
||||||
|
extra = 1
|
||||||
|
|
||||||
|
|
||||||
|
class NonSortableNoteInline(admin.StackedInline):
|
||||||
|
model = NonSortableNote
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class ProjectAdmin(SortableAdmin):
|
class ProjectAdmin(SortableAdmin):
|
||||||
inlines = [CreditInline, NoteInline, GenericNoteInline]
|
inlines = [
|
||||||
|
CreditInline, NoteInline, GenericNoteInline,
|
||||||
|
NonSortableCreditInline, NonSortableNoteInline
|
||||||
|
]
|
||||||
list_display = ['__unicode__', 'category']
|
list_display = ['__unicode__', 'category']
|
||||||
|
|
||||||
admin.site.register(Project, ProjectAdmin)
|
admin.site.register(Project, ProjectAdmin)
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,25 @@ class Note(Sortable):
|
||||||
return self.text
|
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
|
# A generic bound model
|
||||||
class GenericNote(SimpleModel, Sortable):
|
class GenericNote(SimpleModel, Sortable):
|
||||||
content_type = models.ForeignKey(ContentType,
|
content_type = models.ForeignKey(ContentType,
|
||||||
|
|
@ -97,6 +116,7 @@ class Component(SimpleModel, Sortable):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Person(Sortable):
|
class Person(Sortable):
|
||||||
class Meta(Sortable.Meta):
|
class Meta(Sortable.Meta):
|
||||||
verbose_name_plural = 'People'
|
verbose_name_plural = 'People'
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue