Add unit field to theoretical max

This commit is contained in:
Gabriel Augendre 2018-03-04 20:39:48 +01:00
parent 45d5879596
commit 8edc9c03f4
No known key found for this signature in database
GPG key ID: F360212F958357D4
3 changed files with 54 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin 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) @admin.register(Room)
@ -26,3 +26,8 @@ class SessionAdmin(admin.ModelAdmin):
@admin.register(Round) @admin.register(Round)
class RoundAdmin(admin.ModelAdmin): class RoundAdmin(admin.ModelAdmin):
pass pass
@admin.register(Unit)
class UnitAdmin(admin.ModelAdmin):
pass

View file

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

View file

@ -55,6 +55,17 @@ class Setting(models.Model):
return f'{self.name}={self.value}' 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 TheoreticalMax(models.Model):
class Meta: class Meta:
verbose_name = 'maximum théorique' verbose_name = 'maximum théorique'
@ -68,9 +79,15 @@ class TheoreticalMax(models.Model):
) )
date = models.DateField('date') date = models.DateField('date')
value = models.FloatField('valeur') value = models.FloatField('valeur')
unit = models.ForeignKey(
verbose_name='unité',
to=Unit,
on_delete=models.PROTECT,
null=True
)
def __str__(self): def __str__(self):
return f'{self.value} le {self.date}' return f'{self.value} {self.unit.name} le {self.date}'
class Session(models.Model): class Session(models.Model):