1
0

Add select able event backgrounds

This commit is contained in:
Marcel Schwarz 2023-07-24 20:26:54 +02:00
parent f0e512de6b
commit ab71d062cf
4 changed files with 48 additions and 1 deletions

View File

@ -1,7 +1,8 @@
from django.contrib import admin
# Register your models here.
from .models import Tobacco, TobaccoCategory, ClubhausEvent, EventDate, EventDateVote, VotingUser, Setting
from .models import Tobacco, TobaccoCategory, ClubhausEvent, EventDate, EventDateVote, VotingUser, Setting, \
EventBackground
@admin.register(Tobacco)
@ -51,6 +52,12 @@ class ClubhausEventAdmin(admin.ModelAdmin):
]
@admin.register(EventBackground)
class EventBackgroundAdmin(admin.ModelAdmin):
list_display = ("id", "name", "picture")
ordering = ("id",)
@admin.register(Setting)
class SettingAdmin(admin.ModelAdmin):
list_display = ("name", "active")

View File

@ -0,0 +1,27 @@
# Generated by Django 4.2 on 2023-04-30 18:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0023_setting_unique_name'),
]
operations = [
migrations.CreateModel(
name='EventBackground',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=200)),
('picture', models.ImageField(blank=True, upload_to='event_backgrounds/')),
],
),
migrations.AddField(
model_name='clubhausevent',
name='background_picture',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='homepage.eventbackground'),
),
]

View File

@ -38,11 +38,20 @@ class ClubhausEvent(models.Model):
location = models.TextField(blank=True)
beverages = models.TextField(blank=True)
food = models.TextField(blank=True)
background_picture = models.ForeignKey(to="EventBackground", on_delete=models.DO_NOTHING, blank=True, null=True)
def __str__(self):
return f"{self.name}"
class EventBackground(models.Model):
name = models.CharField(max_length=200, blank=True)
picture = models.ImageField(upload_to="event_backgrounds/", null=False, blank=True, )
def __str__(self):
return f"{self.name} ({self.id})"
class EventDateVote(models.Model):
voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE)
date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE)

View File

@ -5,7 +5,11 @@
{% block extra_header_block %}
<style>
.cus-bg-image {
{% if next_event.background_picture %}
background-image: url("{% get_media_prefix %}{{ next_event.background_picture.picture }}");
{% else %}
background-image: url("{% static 'homepage/img/background.jpg' %}");
{% endif %}
background-repeat: no-repeat;
background-position: center;
background-size: cover;