diff --git a/project/common/utils.py b/project/common/utils.py new file mode 100644 index 0000000..26d129d --- /dev/null +++ b/project/common/utils.py @@ -0,0 +1,3 @@ + +def round_to_multiple(value, base): + return value - value % base diff --git a/project/home/models.py b/project/home/models.py index 709ea4d..260ffe7 100755 --- a/project/home/models.py +++ b/project/home/models.py @@ -2,7 +2,9 @@ from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailadmin.edit_handlers import FieldPanel from project.blog.models import BlogPage +from project.projects.models import ProjectPage from project.common.models import Entity +from project.common.utils import round_to_multiple class HomePage(Entity): @@ -17,4 +19,7 @@ class HomePage(Entity): def get_context(self, *args, **kwargs): context = super().get_context(*args, **kwargs) context['blog_posts'] = BlogPage.objects.live().order_by('-post_date')[:4] + projects = ProjectPage.objects.live().filter(search_image__isnull=False) + projects_to_show = round_to_multiple(projects.count(), 3) if projects.count() >= 3 else projects.count() + context['projects'] = projects[:projects_to_show] return context diff --git a/templates/home/home_page.html b/templates/home/home_page.html index 3bf7122..7e58cd9 100755 --- a/templates/home/home_page.html +++ b/templates/home/home_page.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% load wagtailcore_tags %} +{% load wagtailcore_tags wagtailimages_tags %} {% block body_class %}template-homepage{% endblock %} @@ -77,6 +77,22 @@
+ {% for project in projects %} +
+ {% image project.image max-1000x1000 as project_image %} + +
+
+
+

+ {{ project.title }} +

+
+
+
+
+
+ {% endfor %}