From bd49b09896ce2022bd91bb2a96c763c9d4937a60 Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 24 Aug 2023 20:58:22 +0200 Subject: [PATCH] upload character pictures --- .gitignore | 4 +++- guild/migrations/0011_character_picture.py | 19 +++++++++++++++++++ guild/models.py | 4 ++++ guild/templates/guild/character_detail.html | 12 +++++++++++- guild/templates/guild/character_form.html | 2 +- guild/views/character.py | 4 ++-- guild_journal/settings/development.py | 4 ++++ guild_journal/settings/production.py | 3 +++ guild_journal/urls.py | 3 +++ 9 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 guild/migrations/0011_character_picture.py diff --git a/.gitignore b/.gitignore index 6769e21..4293c41 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,6 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +media/ \ No newline at end of file diff --git a/guild/migrations/0011_character_picture.py b/guild/migrations/0011_character_picture.py new file mode 100644 index 0000000..c94a8cf --- /dev/null +++ b/guild/migrations/0011_character_picture.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.1 on 2023-08-24 18:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0010_playsessionsummaryversion"), + ] + + operations = [ + migrations.AddField( + model_name="character", + name="picture", + field=models.ImageField( + blank=True, null=True, upload_to="", verbose_name="Character Picture" + ), + ), + ] diff --git a/guild/models.py b/guild/models.py index 5e52c18..f448f2b 100644 --- a/guild/models.py +++ b/guild/models.py @@ -91,6 +91,10 @@ class Character(models.Model): blank=True, ) + picture = models.ImageField( + _("Character Picture"), null=True, blank=True, upload_to="uploads/" + ) + created_at = models.DateTimeField(_("created at"), auto_now_add=True) updated_at = models.DateTimeField(_("updated at"), auto_now=True) diff --git a/guild/templates/guild/character_detail.html b/guild/templates/guild/character_detail.html index 40471fb..c16cfe1 100644 --- a/guild/templates/guild/character_detail.html +++ b/guild/templates/guild/character_detail.html @@ -27,7 +27,17 @@ -

{{character.description|md|safe}}

+
+
+ + + + +

{{character.description|md|safe}}

+
+
+ +

Session History

diff --git a/guild/templates/guild/character_form.html b/guild/templates/guild/character_form.html index cc1f41f..412f11f 100644 --- a/guild/templates/guild/character_form.html +++ b/guild/templates/guild/character_form.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block content %} -
+ {% csrf_token %} {{ form.as_p }} {% if object %} diff --git a/guild/views/character.py b/guild/views/character.py index 8aab3e0..b5e60ea 100644 --- a/guild/views/character.py +++ b/guild/views/character.py @@ -12,7 +12,7 @@ class CharacterListView(LoginRequiredMixin, ListView): class CreateCharacterView(LoginRequiredMixin, CreateView): model = Character - fields = ["name", "description", "player", "status"] + fields = ["name", "picture", "description", "player", "status"] class CharacterDetailView(LoginRequiredMixin, DetailView): @@ -33,7 +33,7 @@ class CharacterDetailView(LoginRequiredMixin, DetailView): class CharacterUpdateView(LoginRequiredMixin, UpdateView): model = Character - fields = ["name", "description", "player", "status"] + fields = ["name", "picture", "description", "player", "status"] class CharacterDeleteView(LoginRequiredMixin, DeleteView): diff --git a/guild_journal/settings/development.py b/guild_journal/settings/development.py index 90a837f..2a9000a 100644 --- a/guild_journal/settings/development.py +++ b/guild_journal/settings/development.py @@ -20,3 +20,7 @@ DATABASES = { "NAME": BASE_DIR / "db.sqlite3", } } + + +MEDIA_ROOT = BASE_DIR / "media" +MEDIA_URL = "/media/" diff --git a/guild_journal/settings/production.py b/guild_journal/settings/production.py index 9916afd..bf035f1 100644 --- a/guild_journal/settings/production.py +++ b/guild_journal/settings/production.py @@ -24,3 +24,6 @@ DATABASES = { "NAME": "/data/db.sqlite3", } } + +EDIA_ROOT = "/data/guild_journal/media" +MEDIA_URL = "/media/" diff --git a/guild_journal/urls.py b/guild_journal/urls.py index d89bd1f..8d1a051 100644 --- a/guild_journal/urls.py +++ b/guild_journal/urls.py @@ -16,8 +16,11 @@ Including another URLconf """ from django.contrib import admin from django.urls import include, path +from django.conf import settings +from django.conf.urls.static import static urlpatterns = [ path("admin/", admin.site.urls), path("", include(("guild.urls", "guild"), namespace="guild")), ] +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)