Skip to content
Permalink
Browse files

Registering a Blog Author Snippet

  • Loading branch information
KalobTaulien committed Feb 12, 2019
1 parent 5986eb3 commit de5e86e29802c1548cabb148ca0e41dafcfe928d
Showing with 76 additions and 1 deletion.
  1. +28 −0 blog/migrations/0002_blogauthor.py
  2. +48 −1 blog/models.py
@@ -0,0 +1,28 @@
# Generated by Django 2.1.5 on 2019-02-12 16:01

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0001_squashed_0021'),
('blog', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='BlogAuthor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('website', models.URLField(blank=True, null=True)),
('image', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
],
options={
'verbose_name': 'Blog Author',
'verbose_name_plural': 'Blog Authors',
},
),
]
@@ -2,15 +2,62 @@
from django.db import models
from django.shortcuts import render

from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.admin.edit_handlers import (
FieldPanel,
StreamFieldPanel,
MultiFieldPanel,
)
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.snippets.models import register_snippet


from streams import blocks


class BlogAuthor(models.Model):
"""Blog author for snippets."""

name = models.CharField(max_length=100)
website = models.URLField(blank=True, null=True)
image = models.ForeignKey(
"wagtailimages.Image",
on_delete=models.SET_NULL,
null=True,
blank=False,
related_name="+",
)

panels = [
MultiFieldPanel(
[
FieldPanel("name"),
ImageChooserPanel("image"),
],
heading="Name and Image",
),
MultiFieldPanel(
[
FieldPanel("website"),
],
heading="Links"
)
]

def __str__(self):
"""String repr of this class."""
return self.name

class Meta: # noqa
verbose_name = "Blog Author"
verbose_name_plural = "Blog Authors"


register_snippet(BlogAuthor)


class BlogListingPage(RoutablePageMixin, Page):
"""Listing page lists all the Blog Detail Pages."""

1 comment on commit de5e86e

Please sign in to comment.
You can’t perform that action at this time.