From c5e811878b28765cd81ddba6b6de3876f6948fec Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 21 Jul 2022 13:50:36 +0100 Subject: [PATCH] Begin implementing the CMS functions --- core/migrations/0006_contentblock_page.py | 18 ++++++++++++++++++ core/models.py | 16 +++++++++++++--- core/templates/index.html | 15 +++------------ core/views/__init__.py | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 core/migrations/0006_contentblock_page.py diff --git a/core/migrations/0006_contentblock_page.py b/core/migrations/0006_contentblock_page.py new file mode 100644 index 0000000..b1a9020 --- /dev/null +++ b/core/migrations/0006_contentblock_page.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.6 on 2022-07-13 14:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0005_contentblock_image1_contentblock_image2_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='contentblock', + name='page', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/core/models.py b/core/models.py index 1d4ad20..603b1f8 100644 --- a/core/models.py +++ b/core/models.py @@ -72,6 +72,7 @@ class Session(models.Model): class ContentBlock(models.Model): user = models.ForeignKey(User, on_delete=models.PROTECT) position = models.IntegerField() + page = models.CharField(max_length=255, null=True, blank=True) title = models.CharField(max_length=255, null=True, blank=True) column1 = models.TextField(null=True, blank=True) column2 = models.TextField(null=True, blank=True) @@ -80,15 +81,24 @@ class ContentBlock(models.Model): image2 = models.CharField(max_length=255, null=True, blank=True) image3 = models.CharField(max_length=255, null=True, blank=True) + def __str__(self): + return f"[{self.position}] {self.page} {self.title}" + def save(self, *args, **kwargs): """ Override the save function to blank fields. """ - if self.column1 == "NONE": + if self.column1 == "": self.column1 = None - if self.column2 == "NONE": + if self.column2 == "": self.column2 = None - if self.column3 == "NONE": + if self.column3 == "": self.column3 = None + if self.image1 == "": + self.image1 = None + if self.image2 == "": + self.image2 = None + if self.image3 == "": + self.image3 = None super().save(*args, **kwargs) diff --git a/core/templates/index.html b/core/templates/index.html index f0c1333..edb4add 100644 --- a/core/templates/index.html +++ b/core/templates/index.html @@ -7,52 +7,43 @@ {% if block.title is not None %}

{{ block.title }}

{% endif %} +
{% if block.column1 is not None %}
-
+ {{ block.column1 }}
-
{% endif %} {% if block.column2 is not None %}
-
{{ block.column2 }} -
{% endif %} {% if block.column3 is not None %}
-
{{ block.column3 }} -
{% endif %}
{% if block.image1 is not None %}
-
-
{% endif %} {% if block.image2 is not None %}
-
-
{% endif %} {% if block.image3 is not None %}
-
-
{% endif %}
+
{% endfor %} {% endblock %} diff --git a/core/views/__init__.py b/core/views/__init__.py index 5391f57..8d32817 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -22,7 +22,7 @@ class Home(View): template_name = "index.html" def get(self, request): - blocks = ContentBlock.objects.all().order_by("position") + blocks = ContentBlock.objects.filter(page="home").order_by("position") print("BLOCKS", blocks) print("ITER", [x.position for x in blocks]) context = {"blocks": blocks}