Begin implementing the CMS functions
This commit is contained in:
parent
3ff8cd6166
commit
c5e811878b
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
|
|
@ -7,52 +7,43 @@
|
|||
{% if block.title is not None %}
|
||||
<h1 class="title">{{ block.title }}</h1>
|
||||
{% endif %}
|
||||
<div class="box">
|
||||
<div class="columns">
|
||||
{% if block.column1 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
|
||||
{{ block.column1 }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if block.column2 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
{{ block.column2 }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if block.column3 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
{{ block.column3 }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="columns">
|
||||
{% if block.image1 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
<img src="{% static block.image1 %}">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if block.image2 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
<img src="{% static block.image2 %}">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if block.image3 is not None %}
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
<img src="{% static block.image3 %}">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue