models.py 1.82 KB
Newer Older
Mediatek's avatar
Mediatek committed
1
from django.db import models
Mediatek's avatar
Mediatek committed
2
from django.core.validators import MinValueValidator
Mediatek's avatar
Mediatek committed
3 4

class Auteur(models.Model):
Mediatek's avatar
Mediatek committed
5
    nom = models.CharField(max_length=255, unique=True)
Mediatek's avatar
Mediatek committed
6 7 8 9 10 11 12

    def __str__(self):
        return self.nom

class Media(models.Model):
    titre = models.CharField(max_length=255)
    cote = models.CharField(max_length=31)
Mediatek's avatar
Mediatek committed
13
    auteur = models.ManyToManyField('Auteur') 
Mediatek's avatar
Mediatek committed
14 15 16
#    type = TODO

    def __str__(self):
17
        return str(self.titre) + ' - ' + str(self.auteur.all().first())
Mediatek's avatar
Mediatek committed
18 19 20 21 22 23 24 25

class Emprunt(models.Model):
    media = models.ForeignKey('Media', on_delete=models.PROTECT) 
    user = models.ForeignKey('users.User', on_delete=models.PROTECT) 
    date_emprunt = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
    date_rendu = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S', blank=True, null=True)
    permanencier_emprunt = models.ForeignKey('users.User', on_delete=models.PROTECT, related_name='user_permanencier_emprunt')
    permanencier_rendu = models.ForeignKey('users.User', on_delete=models.PROTECT, related_name='user_permanencier_rendu', blank=True, null=True) 
Mediatek's avatar
Mediatek committed
26 27 28

    def __str__(self):
        return str(self.media) + str(self.user)
Mediatek's avatar
Mediatek committed
29 30
 

31 32
class Jeu(models.Model):
    DUREE = (
Mediatek's avatar
Mediatek committed
33 34 35
            ('-1h', '-1h'),
            ('1-2h', '1-2h'),
            ('2-3h', '2-3h'),
Mediatek's avatar
Mediatek committed
36
            ('3-4h', '3-4h'),
Mediatek's avatar
Mediatek committed
37
            ('4h+', '4h+'),
38
            )
Mediatek's avatar
Mediatek committed
39 40


41 42 43
    nom = models.CharField(max_length=255)
    proprietaire = models.ForeignKey('users.User', on_delete=models.PROTECT) 
    duree = models.CharField(choices=DUREE, max_length=255)
Mediatek's avatar
Mediatek committed
44 45
    nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)])
    nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)])
46 47
    comment = models.CharField(help_text="Commentaire", max_length=255, blank=True, null=True)

Mediatek's avatar
Mediatek committed
48 49
    def __str__(self):
        return str(self.nom)