diff --git a/htmleditor/admin.py b/htmleditor/admin.py index b51ccc1b60d17cf07156aa87e68dfd8d1b1c4b63..874ea00da229fd0fa89243c72d61c139cc252ade 100644 --- a/htmleditor/admin.py +++ b/htmleditor/admin.py @@ -5,7 +5,7 @@ from django.contrib import admin from django.utils.http import is_safe_url from django.http import HttpResponseRedirect -from adminsortable.admin import SortableAdmin +from adminsortable.admin import SortableAdmin, SortableTabularInline from htmleditor.models import ( Image, @@ -94,7 +94,7 @@ class DocumentAdmin(NextMixin, admin.ModelAdmin): search_fields = ['name'] -class TabDocumentInline(admin.TabularInline): +class TabDocumentInline(SortableTabularInline): """Simple TabDocument Inline""" model = TabDocument diff --git a/htmleditor/migrations/0026_tabdocument_sorting.py b/htmleditor/migrations/0026_tabdocument_sorting.py new file mode 100644 index 0000000000000000000000000000000000000000..7400d656a437aa6b3be234afd1033fed7269aade --- /dev/null +++ b/htmleditor/migrations/0026_tabdocument_sorting.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-06-26 16:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('htmleditor', '0025_add_index_view'), + ] + + operations = [ + migrations.AlterModelOptions( + name='tabdocument', + options={'ordering': ['order']}, + ), + migrations.AddField( + model_name='tabdocument', + name='order', + field=models.PositiveIntegerField(db_index=True, default=0, editable=False), + ), + ] diff --git a/htmleditor/models.py b/htmleditor/models.py index 187073712be42251650e180be73cbaf973b0e1f3..d2dd842e75ecffc7a2dbdbb9b178ab88fe3c06dc 100644 --- a/htmleditor/models.py +++ b/htmleditor/models.py @@ -309,7 +309,7 @@ class NavigationNode(SortableMixin): return text -class TabDocument(models.Model): +class TabDocument(SortableMixin): """A document is shown inside a tabbed view""" title = models.CharField(max_length=MAX_LENGTH, help_text="This is the tab text") @@ -317,6 +317,12 @@ class TabDocument(models.Model): navigation_node = models.ForeignKey('NavigationNode', models.CASCADE, related_name='tabs') + order = models.PositiveIntegerField(default=0, editable=False, + db_index=True) + + class Meta: + ordering = ['order'] + def __str__(self): return self.title