Преглед на файлове

restore BlogPage.subtitle and inject Panel into appropriate position

David Ray преди 8 години
родител
ревизия
cace34cd65
променени са 2 файла, в които са добавени 4 реда и са изтрити 4 реда
  1. 0 4
      bakerydemo/blog/migrations/0005_auto_20170220_0111.py
  2. 4 0
      bakerydemo/blog/models.py

+ 0 - 4
bakerydemo/blog/migrations/0005_auto_20170220_0111.py

@@ -13,10 +13,6 @@ class Migration(migrations.Migration):
     ]
     ]
 
 
     operations = [
     operations = [
-        migrations.RemoveField(
-            model_name='blogpage',
-            name='subtitle',
-        ),
         migrations.AlterField(
         migrations.AlterField(
             model_name='blogindexpage',
             model_name='blogindexpage',
             name='image',
             name='image',

+ 4 - 0
bakerydemo/blog/models.py

@@ -46,6 +46,7 @@ class BlogPage(BasePageFieldsMixin, Page):
     """
     """
     A Blog Page (Post)
     A Blog Page (Post)
     """
     """
+    subtitle = models.CharField(blank=True, max_length=255)
     tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
     tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
     date_published = models.DateField("Date article published", blank=True, null=True)
     date_published = models.DateField("Date article published", blank=True, null=True)
     body = StreamField(
     body = StreamField(
@@ -60,6 +61,9 @@ class BlogPage(BasePageFieldsMixin, Page):
             panels=None, min_num=1),
             panels=None, min_num=1),
         FieldPanel('tags'),
         FieldPanel('tags'),
     ]
     ]
+    # Inject subtitle panel after title field
+    title_index = next((i for i, panel in enumerate(content_panels) if panel.field_name == 'title'), -1)  # noqa
+    content_panels.insert(title_index + 1, FieldPanel('subtitle'))
 
 
     search_fields = Page.search_fields + [
     search_fields = Page.search_fields + [
         index.SearchField('title'),
         index.SearchField('title'),