1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-07-07 19:20:13 +02:00

Replace old models by new models to update DB structure

This commit is contained in:
2021-10-26 11:37:32 +02:00
parent 39e345ee67
commit e3bab2389c
4 changed files with 467 additions and 19 deletions

View File

@ -5,6 +5,7 @@
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
from polymorphic.models import PolymorphicModel
from .fields import ISBNField
@ -30,7 +31,86 @@ class Author(models.Model):
ordering = ['name']
class Comic(models.Model):
class Borrowable(PolymorphicModel):
title = models.CharField(
max_length=255,
verbose_name=_("title"),
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title
class Meta:
verbose_name = _('borrowable')
verbose_name_plural = _('borrowables')
class Medium(Borrowable):
external_url = models.URLField(
verbose_name=_('external URL'),
blank=True,
)
side_identifier = models.CharField(
verbose_name=_('side identifier'),
max_length=255,
)
authors = models.ManyToManyField(
'Author',
verbose_name=_('authors'),
)
class Meta:
verbose_name = _("medium")
verbose_name_plural = _("media")
class Book(Medium):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
blank=True,
null=True,
)
subtitle = models.CharField(
verbose_name=_('subtitle'),
max_length=255,
blank=True,
)
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 = _("book")
verbose_name_plural = _("books")
class OldComic(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
@ -95,7 +175,14 @@ class Comic(models.Model):
ordering = ['title', 'subtitle']
class Manga(models.Model):
class Comic(Book):
class Meta:
verbose_name = _("comic")
verbose_name_plural = _("comics")
ordering = ['title', 'subtitle']
class OldManga(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
@ -157,7 +244,14 @@ class Manga(models.Model):
ordering = ['title']
class Novel(models.Model):
class Manga(Book):
class Meta:
verbose_name = _("manga")
verbose_name_plural = _("mangas")
ordering = ['title', 'subtitle']
class OldNovel(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
@ -219,7 +313,14 @@ class Novel(models.Model):
ordering = ['title', 'subtitle']
class Vinyl(models.Model):
class Novel(Book):
class Meta:
verbose_name = _("novel")
verbose_name_plural = _("novels")
ordering = ['title', 'subtitle']
class OldVinyl(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
@ -258,7 +359,22 @@ class Vinyl(models.Model):
ordering = ['title']
class CD(models.Model):
class Vinyl(Medium):
rpm = models.PositiveIntegerField(
verbose_name=_('rounds per minute'),
choices=[
(33, _('33 RPM')),
(45, _('45 RPM')),
],
)
class Meta:
verbose_name = _("vinyl")
verbose_name_plural = _("vinyls")
ordering = ['title']
class OldCD(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
@ -289,7 +405,14 @@ class CD(models.Model):
ordering = ['title']
class Review(models.Model):
class CD(Medium):
class Meta:
verbose_name = _("CD")
verbose_name_plural = _("CDs")
ordering = ['title']
class OldReview(models.Model):
title = models.CharField(
verbose_name=_('title'),
max_length=255,
@ -340,6 +463,46 @@ class Review(models.Model):
ordering = ['title', 'number']
class Review(Borrowable):
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 = _("review")
verbose_name_plural = _("reviews")
ordering = ['title', 'number']
class FutureMedium(models.Model):
isbn = ISBNField(
_('ISBN'),
@ -375,7 +538,7 @@ class FutureMedium(models.Model):
class Emprunt(models.Model):
media = models.ForeignKey(
'Comic',
'media.Borrowable',
on_delete=models.PROTECT,
)
user = models.ForeignKey(
@ -417,7 +580,7 @@ class Emprunt(models.Model):
ordering = ['-date_emprunt']
class Game(models.Model):
class OldGame(models.Model):
DURATIONS = (
('-1h', '-1h'),
('1-2h', '1-2h'),
@ -426,7 +589,7 @@ class Game(models.Model):
('4h+', '4h+'),
)
name = models.CharField(
title = models.CharField(
max_length=255,
verbose_name=_("name"),
)
@ -455,9 +618,50 @@ class Game(models.Model):
)
def __str__(self):
return str(self.name)
return str(self.title)
class Meta:
verbose_name = _("game")
verbose_name_plural = _("games")
ordering = ['name']
ordering = ['title']
class Game(Borrowable):
DURATIONS = (
('-1h', '-1h'),
('1-2h', '1-2h'),
('2-3h', '2-3h'),
('3-4h', '3-4h'),
('4h+', '4h+'),
)
owner = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
verbose_name=_("owner"),
)
duration = models.CharField(
choices=DURATIONS,
max_length=255,
verbose_name=_("duration"),
)
players_min = models.IntegerField(
validators=[MinValueValidator(1)],
verbose_name=_("minimum number of players"),
)
players_max = models.IntegerField(
validators=[MinValueValidator(1)],
verbose_name=_('maximum number of players'),
)
comment = models.CharField(
max_length=255,
blank=True,
verbose_name=_('comment'),
)
def __str__(self):
return str(self.title)
class Meta:
verbose_name = _("game")
verbose_name_plural = _("games")
ordering = ['title']