From 004195e843e4982433bee268435b63255a95029a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 24 Nov 2016 21:44:08 +0000 Subject: [PATCH] add blog model stuff --- project/blog/__init__.py | 0 project/blog/migrations/0001_initial.py | 34 +++++++++++++++++++++++ project/blog/migrations/__init__.py | 0 project/blog/models.py | 32 +++++++++++++++++++++ project/common/migrations/0001_initial.py | 30 ++++++++++++++++++++ project/common/migrations/__init__.py | 0 project/common/models.py | 11 ++++++++ project/home/models.py | 2 -- project/settings.py | 1 + templates/blog/blog_page.html | 18 ++++++++++++ templates/common/section_index_page.html | 11 ++++++++ 11 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 project/blog/__init__.py create mode 100644 project/blog/migrations/0001_initial.py create mode 100644 project/blog/migrations/__init__.py create mode 100644 project/blog/models.py create mode 100644 project/common/migrations/0001_initial.py create mode 100644 project/common/migrations/__init__.py create mode 100644 project/common/models.py create mode 100644 templates/blog/blog_page.html create mode 100644 templates/common/section_index_page.html diff --git a/project/blog/__init__.py b/project/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/blog/migrations/0001_initial.py b/project/blog/migrations/0001_initial.py new file mode 100644 index 0000000..5b5e658 --- /dev/null +++ b/project/blog/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-24 20:51 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.wagtailcore.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('wagtailcore', '0030_index_on_pagerevision_created_at'), + ('wagtailimages', '0015_fill_filter_spec_field'), + ] + + operations = [ + migrations.CreateModel( + name='BlogPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('date', models.DateField(verbose_name='Post date')), + ('intro', models.CharField(max_length=250)), + ('body', wagtail.wagtailcore.fields.RichTextField(blank=True)), + ('main_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/project/blog/migrations/__init__.py b/project/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/blog/models.py b/project/blog/models.py new file mode 100644 index 0000000..6ec2c80 --- /dev/null +++ b/project/blog/models.py @@ -0,0 +1,32 @@ +from django.db import models + +from wagtail.wagtailcore.models import Page +from wagtail.wagtailcore.fields import RichTextField +from wagtail.wagtailadmin.edit_handlers import FieldPanel +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel +from wagtail.wagtailsearch import index + + +class BlogPage(Page): + main_image = models.ForeignKey( + 'wagtailimages.Image', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + date = models.DateField("Post date") + intro = models.CharField(max_length=250) + body = RichTextField(blank=True) + + search_fields = Page.search_fields + [ + index.SearchField('intro'), + index.SearchField('body'), + ] + + content_panels = Page.content_panels + [ + FieldPanel('date'), + ImageChooserPanel('main_image'), + FieldPanel('intro'), + FieldPanel('body'), + ] diff --git a/project/common/migrations/0001_initial.py b/project/common/migrations/0001_initial.py new file mode 100644 index 0000000..689f3aa --- /dev/null +++ b/project/common/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-24 21:20 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.wagtailcore.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('wagtailcore', '0030_index_on_pagerevision_created_at'), + ] + + operations = [ + migrations.CreateModel( + name='SectionIndexPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('intro', wagtail.wagtailcore.fields.RichTextField(blank=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/project/common/migrations/__init__.py b/project/common/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/common/models.py b/project/common/models.py new file mode 100644 index 0000000..3cca75b --- /dev/null +++ b/project/common/models.py @@ -0,0 +1,11 @@ +from wagtail.wagtailcore.models import Page +from wagtail.wagtailcore.fields import RichTextField +from wagtail.wagtailadmin.edit_handlers import FieldPanel + + +class SectionIndexPage(Page): + intro = RichTextField(blank=True) + + content_panels = Page.content_panels + [ + FieldPanel('intro', classname="full") + ] diff --git a/project/home/models.py b/project/home/models.py index 08a5aa2..2cd83c8 100755 --- a/project/home/models.py +++ b/project/home/models.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailadmin.edit_handlers import FieldPanel diff --git a/project/settings.py b/project/settings.py index eb41e78..677b36e 100755 --- a/project/settings.py +++ b/project/settings.py @@ -45,6 +45,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', + 'project.blog', 'project.common', 'project.home', 'project.search', diff --git a/templates/blog/blog_page.html b/templates/blog/blog_page.html new file mode 100644 index 0000000..4d1f9f7 --- /dev/null +++ b/templates/blog/blog_page.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags wagtailimages_tags %} + +{% block body_class %}template-blogpage{% endblock %} + +{% block content %} +

{{ page.title }}

+

{{ page.date }}

+ + {% if page.main_image %} + {% image page.main_image width-400 %} + {% endif %} + +
{{ page.intro }}
+ + {{ page.body|richtext }} +{% endblock %} diff --git a/templates/common/section_index_page.html b/templates/common/section_index_page.html new file mode 100644 index 0000000..60f75f0 --- /dev/null +++ b/templates/common/section_index_page.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags %} + +{% block body_class %}template-indexpage{% endblock %} + +{% block content %} +

{{ page.title }}

+ +
{{ page.intro|richtext }}
+{% endblock %}