diff --git a/gestioncof/cms/migrations/0002_auto_20180128_1717.py b/gestioncof/cms/migrations/0002_auto_20180128_1717.py new file mode 100644 index 00000000..9b32ab15 --- /dev/null +++ b/gestioncof/cms/migrations/0002_auto_20180128_1717.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.9 on 2018-01-28 16:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cofcms', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='cofdirectoryentrypage', + name='sort_order', + field=models.IntegerField(blank=True, editable=False, null=True), + ), + migrations.AddField( + model_name='cofdirectorypage', + name='alphabetique', + field=models.BooleanField(default=True, verbose_name='Tri par ordre alphabétique ?'), + ), + ] diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 508c9743..da6f6a8b 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -154,9 +154,12 @@ class COFActuPage(Page): # Annuaires (Clubs, partenaires, bonnes adresses) class COFDirectoryPage(Page): introduction = RichTextField("Introduction") - + alphabetique = models.BooleanField("Tri par ordre alphabétique ?", + default=True, blank=True) + content_panels = Page.content_panels + [ FieldPanel('introduction'), + FieldPanel('alphabetique'), ] subpage_types = ['COFActuPage', 'COFDirectoryEntryPage'] @@ -165,8 +168,9 @@ class COFDirectoryPage(Page): @property def entries(self): entries = COFDirectoryEntryPage.objects.live()\ - .descendant_of(self)\ - .order_by("title") + .descendant_of(self) + if self.alphabetique: + entries = entries.order_by("title") return entries class Meta: @@ -174,7 +178,7 @@ class COFDirectoryPage(Page): verbose_name_plural = "Annuaires" -class COFDirectoryEntryPage(Page): +class COFDirectoryEntryPage(Page, Orderable): body = RichTextField("Description") links = StreamField([ ('lien', blocks.StructBlock([