From 8edc9c03f4c093ef0dcd5374887559d25e0c9403 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 4 Mar 2018 20:39:48 +0100 Subject: [PATCH] Add unit field to theoretical max --- gym/admin.py | 7 +++++- gym/migrations/0006_auto_20180304_2037.py | 30 +++++++++++++++++++++++ gym/models.py | 19 +++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 gym/migrations/0006_auto_20180304_2037.py diff --git a/gym/admin.py b/gym/admin.py index 5d256f9..d5adebc 100644 --- a/gym/admin.py +++ b/gym/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from gym.models import Room, Equipment, Setting, TheoreticalMax, Session, Round +from gym.models import Room, Equipment, TheoreticalMax, Session, Round, Unit @admin.register(Room) @@ -26,3 +26,8 @@ class SessionAdmin(admin.ModelAdmin): @admin.register(Round) class RoundAdmin(admin.ModelAdmin): pass + + +@admin.register(Unit) +class UnitAdmin(admin.ModelAdmin): + pass diff --git a/gym/migrations/0006_auto_20180304_2037.py b/gym/migrations/0006_auto_20180304_2037.py new file mode 100644 index 0000000..0bcf54e --- /dev/null +++ b/gym/migrations/0006_auto_20180304_2037.py @@ -0,0 +1,30 @@ +# Generated by Django 2.0.2 on 2018-03-04 19:37 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gym', '0005_auto_20180304_1025'), + ] + + operations = [ + migrations.CreateModel( + name='Unit', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='nom')), + ], + options={ + 'verbose_name': 'unité', + 'verbose_name_plural': 'unités', + }, + ), + migrations.AddField( + model_name='theoreticalmax', + name='unit', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='gym.Unit', verbose_name='unité'), + ), + ] diff --git a/gym/models.py b/gym/models.py index 2b81a6f..bce3c72 100644 --- a/gym/models.py +++ b/gym/models.py @@ -55,6 +55,17 @@ class Setting(models.Model): return f'{self.name}={self.value}' +class Unit(models.Model): + class Meta: + verbose_name = 'unité' + verbose_name_plural = 'unités' + + name = models.CharField('nom', max_length=50) + + def __str__(self): + return self.name + + class TheoreticalMax(models.Model): class Meta: verbose_name = 'maximum théorique' @@ -68,9 +79,15 @@ class TheoreticalMax(models.Model): ) date = models.DateField('date') value = models.FloatField('valeur') + unit = models.ForeignKey( + verbose_name='unité', + to=Unit, + on_delete=models.PROTECT, + null=True + ) def __str__(self): - return f'{self.value} le {self.date}' + return f'{self.value} {self.unit.name} le {self.date}' class Session(models.Model):