Try to add gymnast picture.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Gregory Trullemans 2021-12-21 08:50:57 +01:00
parent 5991ec221a
commit 27f7502489
10 changed files with 63 additions and 8 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ ENV/
env.bak/
venv.bak/
data/
static/img/gymnasts/
# Visual Studio Code #
.vscode/*

View File

@ -135,6 +135,11 @@ STATIC_URL = "/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATIC_ROOT = BASE_DIR / 'staticfiles'
# Media root/url
MEDIA_URL = "/static/img/gymnast/" # https://media.khana.be
MEDIA_ROOT = os.path.join(BASE_DIR, "/static/img/gymnast")
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

View File

@ -61,6 +61,13 @@
{% if form.hours_by_week.errors %}&nbsp;<span class="btn btn-sm btn-danger-outline">{% for error in form.hours_by_week.errors %}{{error}}{% endfor %}</span>{% endif %}
</div>
</div>
<div class="form-group row {% if form.picture.errors %}has-error has-feedback{% endif %}">
<label for="id_picture" class="col-4 col-sm-2 col-md-3 col-lg-3 col-xl-3 col-form-label">Picture</label>
<div class="col-8 col-sm-9 col-md-9 col-lg-9 col-xl-9">
{{ form.picture }}
{% if form.picture.errors %}&nbsp;<span class="btn btn-sm btn-danger-outline">{% for error in form.picture.errors %}{{error}}{% endfor %}</span>{% endif %}
</div>
</div>
{% if jumperid %}
<div class="form-group row {% if form.is_active.errors %}has-error has-feedback{% endif %}">
<label for="id_is_active" class="col-4 col-sm-2 col-md-3 col-lg-3 col-xl-3 col-form-label">Is active</label>
@ -70,6 +77,7 @@
</div>
</div>
{% endif %}
{{ form.picture }}
<div class="form-group text-center">
<input type="submit" value="Save" class="btn btn-fill btn-warning" />
</div>

View File

@ -16,21 +16,22 @@
{% if gymnast.picture %}
<img src="{{ gymnast.picture.url }}" alt="{{ gymnast }}" class="avatar">
{% endif %}
<h4 class="title">{{ gymnast.first_name }} {{ gymnast.last_name }}</h4>
<h4 class="title mb-2">{{ gymnast.first_name }} {{ gymnast.last_name }}</h4>
</a>
<p class="description">
{{ gymnast.club.name }}
</p>
</div>
<div class="card-description">
<div class="card-description mt-2">
<b>{{ gymnast.age }} years</b> ({{ gymnast.birthdate | date:"d F Y" }})<span class="text-info"><b>{{ gymnast.get_orientation_display }}</b></span><br />
{% if height_weight %}
<b>{{ height_weight.0.height }}cm - {{ height_weight.0.weight }}kg</b> ({{ height_weight.0.date | date:"d-m-Y" }})<br />
{% endif %}
<b>{{ gymnast.trainings_by_week }} training/week</b> for <b>{{ gymnast.hours_by_week }} hours/week</b><br />
<b>{{ gymnast.trainings_by_week }} training/week</b> for <b>{{ gymnast.hours_by_week }} hours/week</b>
<br />
<br />
<b><u>Bests Scores</u></b>
<ul>
<ul class="mb-0">
{% if best_straightjump %}
<li><b>Straight jump</b> : <b>{{ best_straightjump.0.tof }}</b> ({{ best_straightjump.0.date | date:"d-m-Y" }})</li>
{% endif %}

View File

@ -12,8 +12,9 @@ class GymnastAdmin(admin.ModelAdmin):
"gender",
"trainings_by_week",
"hours_by_week",
"club",
"picture",
"is_active",
# 'club'
)
list_display = ("last_name", "first_name", "age", "is_active") # , 'club'

View File

@ -1,9 +1,8 @@
"""Formulaires de gestion des données entrantes pour les gymnastes et accidents."""
from django import forms
from .models import Gymnast
from django.forms.widgets import ClearableFileInput
class GymnastForm(forms.ModelForm):
class Meta:
@ -17,6 +16,7 @@ class GymnastForm(forms.ModelForm):
"club",
"trainings_by_week",
"hours_by_week",
"picture",
)
widgets = {
@ -35,6 +35,7 @@ class GymnastForm(forms.ModelForm):
"hours_by_week": forms.TextInput(
attrs={"class": "form-control", "placeholder": "11,5"}
),
"picture": ClearableFileInput(), # forms.ImageField(widget=forms.ClearableFileInput(attrs={'multiple': False})),
}
club_related = forms.CharField(

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2021-12-20 14:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('people', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='gymnast',
name='picture',
field=models.ImageField(blank=True, null=True, upload_to='gymnasts'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2021-12-20 14:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('people', '0002_gymnast_picture'),
]
operations = [
migrations.AlterField(
model_name='gymnast',
name='picture',
field=models.ImageField(blank=True, null=True, upload_to='static/img/gymnasts'),
),
]

View File

@ -34,6 +34,7 @@ class Gymnast(Markdownizable):
verbose_name="# Training by week"
)
hours_by_week = models.PositiveSmallIntegerField(verbose_name="# Hours by week")
picture = models.ImageField(upload_to="static/img/gymnasts", null=True, blank=True)
def __str__(self):
return u"%s, %s" % (self.last_name, self.first_name)

View File

@ -343,6 +343,7 @@ def gymnast_create_or_update(request, gymnast_id=None):
if request.method == "POST":
gymnast_form = GymnastForm(request.POST, instance=gymnast)
print(gymnast_form)
if gymnast_form.is_valid():
gymnast = gymnast_form.save()