11from collections import OrderedDict
22
33from django .core .checks import Warning
4- from django .core .validators import MinValueValidator , RegexValidator
4+ from django .core .validators import RegexValidator
55from django .db import models
6- from django .db .models import Max , Q
6+ from django .db .models import Q
77from django .urls import NoReverseMatch , get_script_prefix , reverse
88from django .utils .encoding import iri_to_uri
99from django .utils .translation import gettext_lazy as _
10- from tree_queries .models import TreeNode , TreeQuerySet
10+ from tree_queries .models import OrderableTreeNode , TreeQuerySet
1111
1212from feincms3 .utils import validation_error
1313
@@ -51,7 +51,7 @@ def applications(self):
5151 )
5252
5353
54- class AbstractPage (TreeNode ):
54+ class AbstractPage (OrderableTreeNode ):
5555 """
5656 Short version: If you want to build a CMS with a hierarchical page
5757 structure, use this base class.
@@ -83,16 +83,6 @@ class AbstractPage(TreeNode):
8383 is_active = models .BooleanField (_ ("is active" ), default = True )
8484 title = models .CharField (_ ("title" ), max_length = 200 )
8585 slug = models .SlugField (_ ("slug" ))
86- position = models .PositiveIntegerField (
87- db_index = True ,
88- editable = False ,
89- validators = [
90- MinValueValidator (
91- limit_value = 1 ,
92- message = _ ("Position is expected to be greater than zero." ),
93- )
94- ],
95- )
9686
9787 # Who even cares about MySQL
9888 path = models .CharField (
@@ -115,9 +105,8 @@ class AbstractPage(TreeNode):
115105
116106 objects = AbstractPageQuerySet .as_manager (with_tree_fields = True )
117107
118- class Meta :
108+ class Meta ( OrderableTreeNode . Meta ) :
119109 abstract = True
120- ordering = ("position" ,)
121110 verbose_name = _ ("page" )
122111 verbose_name_plural = _ ("pages" )
123112
@@ -214,14 +203,6 @@ def save(self, *args, **kwargs):
214203 self .parent .path if self .parent else "/" , self .slug
215204 )
216205
217- if not self .position :
218- self .position = 10 + (
219- self .__class__ ._default_manager .filter (parent_id = self .parent_id )
220- .order_by ()
221- .aggregate (p = Max ("position" ))["p" ]
222- or 0
223- )
224-
225206 super ().save (* args , ** kwargs )
226207
227208 if save_descendants is True or (
0 commit comments