From 74306ae6ca180d010f644c918dfdf42609f5ab7c Mon Sep 17 00:00:00 2001
From: Steven H Johnson <shjohnson.pi@gmail.com>
Date: Sun, 26 Jun 2016 12:28:36 -0400
Subject: [PATCH] Allow tab docs to be sorted

---
 htmleditor/admin.py                           |  4 ++--
 .../migrations/0026_tabdocument_sorting.py    | 24 +++++++++++++++++++
 htmleditor/models.py                          |  8 ++++++-
 3 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 htmleditor/migrations/0026_tabdocument_sorting.py

diff --git a/htmleditor/admin.py b/htmleditor/admin.py
index b51ccc1..874ea00 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 0000000..7400d65
--- /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 1870737..d2dd842 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
 
-- 
GitLab