from django.db import models class Room(models.Model): class Meta: verbose_name = 'salle' verbose_name_plural = 'salles' name = models.CharField('nom', max_length=300) latitude = models.DecimalField('latitude', max_digits=11, decimal_places=8, blank=True) longitude = models.DecimalField('longitude', max_digits=11, decimal_places=8, blank=True) notes = models.TextField('notes', blank=True) def __str__(self): return self.name class Equipment(models.Model): class Meta: verbose_name = 'machine' verbose_name_plural = 'machines' name = models.CharField('nom', max_length=300) room = models.ForeignKey( verbose_name='salle', to=Room, on_delete=models.SET_NULL, related_name='equipments', null=True ) @property def last_theoretical_max(self): return self.theoretical_maxs.order_by('-date').first() def __str__(self): return f'{self.name} ({self.room.name})' class Setting(models.Model): class Meta: verbose_name = 'réglage' verbose_name_plural = 'réglages' equipment = models.ForeignKey( verbose_name='machine', to=Equipment, on_delete=models.CASCADE, related_name='settings' ) name = models.CharField('nom', max_length=200) value = models.CharField('valeur', max_length=200) def __str__(self): return f'{self.name}={self.value}' class TheoreticalMax(models.Model): class Meta: verbose_name = 'maximum théorique' verbose_name_plural = 'maximums théoriques' equipment = models.ForeignKey( verbose_name='machine', to=Equipment, on_delete=models.CASCADE, related_name='theoretical_maxs' ) date = models.DateField('date') value = models.FloatField('valeur') def __str__(self): return f'{self.value}kg le {self.date}' class Session(models.Model): class Meta: verbose_name = 'séance' verbose_name_plural = 'séances' start = models.DateTimeField('date et heure de début') room = models.ForeignKey( verbose_name='salle', to=Room, on_delete=models.SET_NULL, related_name='sessions', null=True ) notes = models.TextField('notes', blank=True) class Round(models.Model): class Meta: verbose_name = 'série' verbose_name_plural = 'séries' repetition_number = models.PositiveIntegerField('nombre de répétitions') equipment = models.ForeignKey( verbose_name='machine', to=Equipment, on_delete=models.CASCADE, related_name='rounds' ) theoretical_max_percentage = models.PositiveIntegerField('pourcentage') chosen_weight = models.FloatField('charge choisie') session = models.ForeignKey( verbose_name='séance', to=Session, on_delete=models.CASCADE, related_name='rounds' ) notes = models.TextField('notes', blank=True)