med/media/models.py

132 lines
3.5 KiB
Python
Raw Normal View History

2019-08-02 12:57:53 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2017-07-03 23:47:22 +00:00
from django.core.validators import MinValueValidator
2019-08-02 12:57:53 +00:00
from django.db import models
from django.utils.translation import gettext_lazy as _
2019-08-11 07:22:22 +00:00
from .fields import ISBNField
2017-06-30 01:25:07 +00:00
class Auteur(models.Model):
2017-07-04 20:29:11 +00:00
nom = models.CharField(max_length=255, unique=True)
2017-06-30 01:25:07 +00:00
def __str__(self):
return self.nom
2019-08-02 12:57:53 +00:00
class Meta:
verbose_name = _("author")
verbose_name_plural = _("authors")
2019-08-11 16:37:04 +00:00
ordering = ['nom']
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class Media(models.Model):
2019-08-11 07:22:22 +00:00
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,
)
2019-08-11 08:49:04 +00:00
side_identifier = models.CharField(
verbose_name=_('side identifier'),
2019-08-11 07:22:22 +00:00
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,
)
2017-06-30 01:25:07 +00:00
def __str__(self):
2019-08-15 09:37:10 +00:00
if self.subtitle:
return "{} : {}".format(self.title, self.subtitle)
else:
return self.title
2017-06-30 01:25:07 +00:00
2019-08-02 12:57:53 +00:00
class Meta:
verbose_name = _("medium")
verbose_name_plural = _("media")
2019-08-11 16:37:04 +00:00
ordering = ['title', 'subtitle']
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class Emprunt(models.Model):
2019-08-02 12:57:53 +00:00
media = models.ForeignKey('Media', on_delete=models.PROTECT)
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
2017-06-30 01:25:07 +00:00
date_emprunt = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
2019-08-08 14:33:05 +00:00
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,
)
2017-07-06 15:30:23 +00:00
def __str__(self):
return str(self.media) + str(self.user)
2019-08-02 12:57:53 +00:00
class Meta:
verbose_name = _("borrowed item")
verbose_name_plural = _("borrowed items")
2019-08-11 16:37:04 +00:00
ordering = ['-date_emprunt']
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
2017-07-03 15:48:56 +00:00
class Jeu(models.Model):
DUREE = (
2019-08-02 12:57:53 +00:00
('-1h', '-1h'),
('1-2h', '1-2h'),
('2-3h', '2-3h'),
('3-4h', '3-4h'),
('4h+', '4h+'),
)
2017-06-30 01:25:07 +00:00
2017-07-03 15:48:56 +00:00
nom = models.CharField(max_length=255)
2019-08-02 12:57:53 +00:00
proprietaire = models.ForeignKey('users.User', on_delete=models.PROTECT)
2017-07-03 15:48:56 +00:00
duree = models.CharField(choices=DUREE, max_length=255)
2017-07-03 23:47:22 +00:00
nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)])
nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)])
2019-08-08 14:33:05 +00:00
comment = models.CharField(help_text="Commentaire", max_length=255,
blank=True, null=True)
2017-07-03 15:48:56 +00:00
2017-07-06 15:30:23 +00:00
def __str__(self):
return str(self.nom)
2019-08-02 12:57:53 +00:00
class Meta:
verbose_name = _("game")
verbose_name_plural = _("games")
2019-08-11 16:37:04 +00:00
ordering = ['nom']