diff --git a/home/migrations/0004_homepage_hero_cta_homepage_hero_cta_link_and_more.py b/home/migrations/0004_homepage_hero_cta_homepage_hero_cta_link_and_more.py new file mode 100644 index 0000000..b98f9e2 --- /dev/null +++ b/home/migrations/0004_homepage_hero_cta_homepage_hero_cta_link_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 5.0.2 on 2024-02-29 20:42 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0003_homepage_body'), + ('wagtailcore', '0091_remove_revision_submitted_for_moderation'), + ('wagtailimages', '0025_alter_image_file_alter_rendition_file'), + ] + + operations = [ + migrations.AddField( + model_name='homepage', + name='hero_cta', + field=models.CharField(blank=True, help_text='Text to display on Call to Action', max_length=255, verbose_name='Hero CTA'), + ), + migrations.AddField( + model_name='homepage', + name='hero_cta_link', + field=models.ForeignKey(blank=True, help_text='Choose a page to link to for the Call to Action', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.page', verbose_name='Hero CTA link'), + ), + migrations.AddField( + model_name='homepage', + name='hero_text', + field=models.CharField(blank=True, help_text='Write an introduction for the site', max_length=255), + ), + migrations.AddField( + model_name='homepage', + name='image', + field=models.ForeignKey(blank=True, help_text='Homepage image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image'), + ), + ] diff --git a/home/models.py b/home/models.py index e6c33f5..9f6b0e9 100644 --- a/home/models.py +++ b/home/models.py @@ -2,11 +2,47 @@ from django.db import models from wagtail.models import Page from wagtail.fields import RichTextField -from wagtail.admin.panels import FieldPanel +from wagtail.admin.panels import FieldPanel, MultiFieldPanel class HomePage(Page): + image = models.ForeignKey( + "wagtailimages.Image", + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name="+", + help_text="Homepage image", + ) + hero_text = models.CharField( + blank=True, + max_length=255, help_text="Write an introduction for the site" + ) + hero_cta = models.CharField( + blank=True, + verbose_name="Hero CTA", + max_length=255, + help_text="Text to display on Call to Action", + ) + hero_cta_link = models.ForeignKey( + "wagtailcore.Page", + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name="+", + verbose_name="Hero CTA link", + help_text="Choose a page to link to for the Call to Action", + ) body = RichTextField(blank=True) content_panels = Page.content_panels + [ + MultiFieldPanel( + [ + FieldPanel("image"), + FieldPanel("hero_text"), + FieldPanel("hero_cta"), + FieldPanel("hero_cta_link"), + ], + heading="Hero section", + ), FieldPanel('body'), ] diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 9a5dc3e..62c3e69 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -1,18 +1,19 @@ {% extends "base.html" %} -{% load static %} -{% load wagtailcore_tags %} +{% load wagtailcore_tags wagtailimages_tags %} {% block body_class %}template-homepage{% endblock %} -{% block extra_css %} - -{% comment %} -Delete the line below if you're just getting started and want to remove the welcome screen! -{% endcomment %} - -{% endblock extra_css %} - - {% block content %} - {{ page.body|richtext }} -{% endblock %} \ No newline at end of file +
{{ page.hero_text }}
+ {% if page.hero_cta_link %} + + {% firstof page.hero_cta page.hero_cta_link.title %} + + {% endif %} +