upload character pictures

This commit is contained in:
Niko Abeler 2023-08-24 20:58:22 +02:00
parent 59e783a4f7
commit bd49b09896
9 changed files with 50 additions and 5 deletions

2
.gitignore vendored
View File

@ -158,3 +158,5 @@ cython_debug/
# 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/
media/

View File

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

View File

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

View File

@ -27,7 +27,17 @@
</div>
</div>
<div class="row">
</div>
<a href="{{character.picture.url}}" style="float:left;margin-right:10px;margin-bottom:10px;">
<img src="{{character.picture.url}}" width="300"/>
</a>
<p>{{character.description|md|safe}}</p>
<div class="column">
</div>
<br>
<h2>Session History</h2>

View File

@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
<form action="" method="post" enctype="multipart/form-data" >
{% csrf_token %}
{{ form.as_p }}
{% if object %}

View File

@ -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):

View File

@ -20,3 +20,7 @@ DATABASES = {
"NAME": BASE_DIR / "db.sqlite3",
}
}
MEDIA_ROOT = BASE_DIR / "media"
MEDIA_URL = "/media/"

View File

@ -24,3 +24,6 @@ DATABASES = {
"NAME": "/data/db.sqlite3",
}
}
EDIA_ROOT = "/data/guild_journal/media"
MEDIA_URL = "/media/"

View File

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