med/media/models.py

125 lines
3.3 KiB
Python

# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
from .fields import ISBNField
class Auteur(models.Model):
nom = models.CharField(max_length=255, unique=True)
def __str__(self):
return self.nom
class Meta:
verbose_name = _("author")
verbose_name_plural = _("authors")
class Media(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
blank=True,
null=True,
)
title = models.CharField(
verbose_name=_('title'),
max_length=255,
)
subtitle = models.CharField(
verbose_name=_('subtitle'),
max_length=255,
blank=True,
null=True,
)
external_url = models.URLField(
verbose_name=_('external URL'),
blank=True,
null=True,
)
side_title = models.CharField(
verbose_name=_('side title'),
max_length=255,
)
authors = models.ManyToManyField(
'Auteur',
verbose_name=_('authors'),
)
number_of_pages = models.PositiveIntegerField(
verbose_name=_('number of pages'),
blank=True,
null=True,
)
publish_date = models.DateField(
verbose_name=_('publish date'),
blank=True,
null=True,
)
def __str__(self):
return str(self.title) + ' - ' + str(self.authors.all().first())
class Meta:
verbose_name = _("medium")
verbose_name_plural = _("media")
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,
)
def __str__(self):
return str(self.media) + str(self.user)
class Meta:
verbose_name = _("borrowed item")
verbose_name_plural = _("borrowed items")
class Jeu(models.Model):
DUREE = (
('-1h', '-1h'),
('1-2h', '1-2h'),
('2-3h', '2-3h'),
('3-4h', '3-4h'),
('4h+', '4h+'),
)
nom = models.CharField(max_length=255)
proprietaire = models.ForeignKey('users.User', on_delete=models.PROTECT)
duree = models.CharField(choices=DUREE, max_length=255)
nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)])
nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)])
comment = models.CharField(help_text="Commentaire", max_length=255,
blank=True, null=True)
def __str__(self):
return str(self.nom)
class Meta:
verbose_name = _("game")
verbose_name_plural = _("games")