1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-27 01:27:10 +00:00
med/media/models.py
Yohann D'ANELLO 963ff25506 Add revues
2020-05-24 15:37:57 +02:00

429 lines
9.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):
name = models.CharField(
max_length=255,
unique=True,
verbose_name=_('name'),
)
note = models.IntegerField(
default=0,
verbose_name=_("note"),
)
def __str__(self):
return self.name
class Meta:
verbose_name = _("author")
verbose_name_plural = _("authors")
ordering = ['name']
class BD(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
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_identifier = models.CharField(
verbose_name=_('side identifier'),
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):
if self.subtitle:
return "{} : {}".format(self.title, self.subtitle)
else:
return self.title
class Meta:
verbose_name = _("BD")
verbose_name_plural = _("BDs")
ordering = ['title', 'subtitle']
class Manga(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
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_identifier = models.CharField(
verbose_name=_('side identifier'),
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 self.title
class Meta:
verbose_name = _("manga")
verbose_name_plural = _("mangas")
ordering = ['title']
class Roman(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
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_identifier = models.CharField(
verbose_name=_('side identifier'),
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 self.title
class Meta:
verbose_name = _("roman")
verbose_name_plural = _("romans")
ordering = ['title', 'subtitle']
class Vinyle(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
)
side_identifier = models.CharField(
verbose_name=_('side identifier'),
max_length=255,
)
rpm = models.PositiveIntegerField(
verbose_name=_('rounds per minute'),
choices=[
(33, _('33 RPM')),
(45, _('45 RPM')),
],
)
authors = models.ManyToManyField(
'Auteur',
verbose_name=_('authors'),
)
def __str__(self):
return self.title
class Meta:
verbose_name = _("vinyle")
verbose_name_plural = _("vinyles")
ordering = ['title']
class CD(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
)
side_identifier = models.CharField(
verbose_name=_('side identifier'),
max_length=255,
)
authors = models.ManyToManyField(
'Auteur',
verbose_name=_('authors'),
)
def __str__(self):
return self.title
class Meta:
verbose_name = _("CD")
verbose_name_plural = _("CDs")
ordering = ['title']
class Revue(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
)
number = models.PositiveIntegerField(
verbose_name=_('number'),
)
year = models.PositiveIntegerField(
verbose_name=_('year'),
null=True,
blank=True,
default=None,
)
month = models.PositiveIntegerField(
verbose_name=_('month'),
null=True,
blank=True,
default=None,
)
day = models.PositiveIntegerField(
verbose_name=_('day'),
null=True,
blank=True,
default=None,
)
double = models.BooleanField(
verbose_name=_('double'),
default=False,
)
def __str__(self):
return self.title + "" + str(self.number)
class Meta:
verbose_name = _("revue")
verbose_name_plural = _("revues")
ordering = ['title', 'number']
class FutureMedia(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
blank=True,
null=True,
)
type = models.CharField(
_('type'),
choices=[
('bd', _('BD')),
('manga', _('Manga')),
('roman', _('Roman')),
],
max_length=8,
)
class Meta:
verbose_name = _("future medium")
verbose_name_plural = _("future media")
def __str__(self):
return "Future medium (ISBN: {isbn})".format(isbn=self.isbn, )
class Emprunt(models.Model):
media = models.ForeignKey(
'BD',
on_delete=models.PROTECT,
)
user = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
verbose_name=_("borrower"),
)
date_emprunt = models.DateTimeField(
verbose_name=_('borrowed on'),
)
date_rendu = models.DateTimeField(
blank=True,
null=True,
verbose_name=_('given back on'),
)
permanencier_emprunt = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
related_name='user_permanencier_emprunt',
verbose_name=_('borrowed with'),
help_text=_('The keyholder that registered this borrowed item.')
)
permanencier_rendu = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
related_name='user_permanencier_rendu',
blank=True,
null=True,
verbose_name=_('given back to'),
help_text=_('The keyholder to whom this item was given back.')
)
def __str__(self):
return str(self.media) + str(self.user)
class Meta:
verbose_name = _("borrowed item")
verbose_name_plural = _("borrowed items")
ordering = ['-date_emprunt']
class Jeu(models.Model):
DUREE = (
('-1h', '-1h'),
('1-2h', '1-2h'),
('2-3h', '2-3h'),
('3-4h', '3-4h'),
('4h+', '4h+'),
)
name = models.CharField(
max_length=255,
verbose_name=_("name"),
)
proprietaire = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
verbose_name=_("owner"),
)
duree = models.CharField(
choices=DUREE,
max_length=255,
verbose_name=_("duration"),
)
nombre_joueurs_min = models.IntegerField(
validators=[MinValueValidator(1)],
verbose_name=_("minimum number of players"),
)
nombre_joueurs_max = models.IntegerField(
validators=[MinValueValidator(1)],
verbose_name=_('maximum number of players'),
)
comment = models.CharField(
max_length=255,
blank=True,
null=True,
verbose_name=_('comment'),
)
def __str__(self):
return str(self.name)
class Meta:
verbose_name = _("game")
verbose_name_plural = _("games")
ordering = ['name']