Begin implementing the CMS functions

This commit is contained in:
Mark Veidemanis 2022-07-21 13:50:36 +01:00
parent 3ff8cd6166
commit c5e811878b
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 35 additions and 16 deletions

View File

@ -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),
),
]

View File

@ -72,6 +72,7 @@ class Session(models.Model):
class ContentBlock(models.Model): class ContentBlock(models.Model):
user = models.ForeignKey(User, on_delete=models.PROTECT) user = models.ForeignKey(User, on_delete=models.PROTECT)
position = models.IntegerField() position = models.IntegerField()
page = models.CharField(max_length=255, null=True, blank=True)
title = 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) column1 = models.TextField(null=True, blank=True)
column2 = 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) image2 = models.CharField(max_length=255, null=True, blank=True)
image3 = 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): def save(self, *args, **kwargs):
""" """
Override the save function to blank fields. Override the save function to blank fields.
""" """
if self.column1 == "NONE": if self.column1 == "":
self.column1 = None self.column1 = None
if self.column2 == "NONE": if self.column2 == "":
self.column2 = None self.column2 = None
if self.column3 == "NONE": if self.column3 == "":
self.column3 = None 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) super().save(*args, **kwargs)

View File

@ -7,52 +7,43 @@
{% if block.title is not None %} {% if block.title is not None %}
<h1 class="title">{{ block.title }}</h1> <h1 class="title">{{ block.title }}</h1>
{% endif %} {% endif %}
<div class="box">
<div class="columns"> <div class="columns">
{% if block.column1 is not None %} {% if block.column1 is not None %}
<div class="column"> <div class="column">
<div class="box">
{{ block.column1 }} {{ block.column1 }}
</div> </div>
</div>
{% endif %} {% endif %}
{% if block.column2 is not None %} {% if block.column2 is not None %}
<div class="column"> <div class="column">
<div class="box">
{{ block.column2 }} {{ block.column2 }}
</div> </div>
</div>
{% endif %} {% endif %}
{% if block.column3 is not None %} {% if block.column3 is not None %}
<div class="column"> <div class="column">
<div class="box">
{{ block.column3 }} {{ block.column3 }}
</div> </div>
</div>
{% endif %} {% endif %}
</div> </div>
<div class="columns"> <div class="columns">
{% if block.image1 is not None %} {% if block.image1 is not None %}
<div class="column"> <div class="column">
<div class="box">
<img src="{% static block.image1 %}"> <img src="{% static block.image1 %}">
</div> </div>
</div>
{% endif %} {% endif %}
{% if block.image2 is not None %} {% if block.image2 is not None %}
<div class="column"> <div class="column">
<div class="box">
<img src="{% static block.image2 %}"> <img src="{% static block.image2 %}">
</div> </div>
</div>
{% endif %} {% endif %}
{% if block.image3 is not None %} {% if block.image3 is not None %}
<div class="column"> <div class="column">
<div class="box">
<img src="{% static block.image3 %}"> <img src="{% static block.image3 %}">
</div> </div>
</div>
{% endif %} {% endif %}
</div> </div>
</div>
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -22,7 +22,7 @@ class Home(View):
template_name = "index.html" template_name = "index.html"
def get(self, request): def get(self, request):
blocks = ContentBlock.objects.all().order_by("position") blocks = ContentBlock.objects.filter(page="home").order_by("position")
print("BLOCKS", blocks) print("BLOCKS", blocks)
print("ITER", [x.position for x in blocks]) print("ITER", [x.position for x in blocks])
context = {"blocks": blocks} context = {"blocks": blocks}