2020-10-11 22:16:00 +02:00
|
|
|
from django.db import models
|
2020-11-22 19:01:21 +01:00
|
|
|
from django.urls import reverse
|
2020-12-13 00:12:06 +01:00
|
|
|
from django.core.exceptions import ValidationError
|
2020-10-11 22:16:00 +02:00
|
|
|
from autoslug import AutoSlugField
|
2020-12-30 00:31:58 +01:00
|
|
|
from website.validators import MaxFileSizeValidator
|
2020-12-27 18:01:37 +01:00
|
|
|
from comments.models import AbstractComment
|
2024-05-02 11:13:34 +02:00
|
|
|
from loans.models import AbstractLoan
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Category(models.Model):
|
2020-12-30 00:31:58 +01:00
|
|
|
name = models.CharField(max_length=256, verbose_name="nom", unique=True)
|
2020-11-22 19:01:21 +01:00
|
|
|
slug = AutoSlugField(populate_from="name", unique=True)
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
class Meta:
|
2020-12-13 00:12:06 +01:00
|
|
|
ordering = ["name"]
|
2024-05-02 14:43:21 +02:00
|
|
|
verbose_name = "étagère"
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-11-22 19:01:21 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse("inventory:category", args=(self.slug,))
|
|
|
|
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
class Tag(models.Model):
|
2020-12-30 00:31:58 +01:00
|
|
|
name = models.CharField(max_length=256, verbose_name="nom", unique=True)
|
2020-11-22 19:01:21 +01:00
|
|
|
slug = AutoSlugField(populate_from="name", unique=True)
|
2020-10-11 22:16:00 +02:00
|
|
|
|
2020-12-13 00:12:06 +01:00
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2020-10-11 22:16:00 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-11-22 19:01:21 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse("inventory:tag", args=(self.slug,))
|
|
|
|
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
class Game(models.Model):
|
2024-07-03 00:52:16 +02:00
|
|
|
title = models.CharField(verbose_name="Nom de l'outil", max_length=256, unique=True)
|
2020-10-11 22:16:00 +02:00
|
|
|
slug = AutoSlugField(populate_from="title", unique=True)
|
2020-12-30 00:31:58 +01:00
|
|
|
|
2020-10-11 22:16:00 +02:00
|
|
|
category = models.ForeignKey(
|
|
|
|
Category, on_delete=models.RESTRICT, verbose_name="catégorie"
|
|
|
|
)
|
|
|
|
tags = models.ManyToManyField(Tag, blank=True, verbose_name="tags")
|
2020-12-30 00:31:58 +01:00
|
|
|
|
|
|
|
description = models.TextField(blank=True, verbose_name="description")
|
|
|
|
image = models.ImageField(
|
|
|
|
upload_to="game_img/",
|
|
|
|
blank=True,
|
|
|
|
verbose_name="image",
|
|
|
|
help_text="L'image doit peser 512 Kio au maximum",
|
|
|
|
validators=[MaxFileSizeValidator(512)],
|
|
|
|
)
|
|
|
|
|
2020-12-13 00:12:06 +01:00
|
|
|
missing_elements = models.TextField(blank=True, verbose_name="pièces manquantes")
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
class Meta:
|
2020-12-13 00:12:06 +01:00
|
|
|
ordering = ["title"]
|
2024-07-03 00:52:16 +02:00
|
|
|
verbose_name = "outil"
|
|
|
|
verbose_name_plural = "outils"
|
2020-10-11 22:16:00 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
2020-11-22 19:01:21 +01:00
|
|
|
|
2020-12-13 00:12:06 +01:00
|
|
|
|
|
|
|
def get_player_range(self):
|
2024-07-03 00:52:16 +02:00
|
|
|
return ""
|
2020-12-13 00:12:06 +01:00
|
|
|
|
2021-01-29 12:07:46 +01:00
|
|
|
def get_duration_range(self):
|
2024-07-03 00:52:16 +02:00
|
|
|
return ""
|
2021-01-29 12:07:46 +01:00
|
|
|
|
2020-11-22 19:01:21 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse("inventory:game", args=(self.slug,))
|
2020-12-13 00:12:06 +01:00
|
|
|
|
|
|
|
|
2020-12-27 18:01:37 +01:00
|
|
|
class GameComment(AbstractComment):
|
|
|
|
commented_object = models.ForeignKey(
|
2024-07-03 00:52:16 +02:00
|
|
|
Game, on_delete=models.CASCADE, related_name="comments", verbose_name="outil"
|
2020-12-13 00:12:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["created_on"]
|
2024-07-03 00:52:16 +02:00
|
|
|
verbose_name = "commentaire sur un outil"
|
|
|
|
verbose_name_plural = "commentaires sur des outils"
|
2020-12-13 00:12:06 +01:00
|
|
|
|
2020-12-27 18:01:37 +01:00
|
|
|
def get_modification_url(self):
|
|
|
|
return reverse(
|
|
|
|
"inventory:modify_game_comment", args=(self.commented_object.slug, self.id)
|
|
|
|
)
|
2024-05-02 11:13:34 +02:00
|
|
|
|
|
|
|
class GameLoan(AbstractLoan):
|
|
|
|
lent_object = models.ForeignKey(
|
|
|
|
Game, on_delete=models.CASCADE,
|
2024-07-03 00:52:16 +02:00
|
|
|
verbose_name="outil emprunté"
|
2024-05-02 11:13:34 +02:00
|
|
|
)
|
2024-05-02 11:31:34 +02:00
|
|
|
|
|
|
|
class Meta(AbstractLoan.Meta):
|
|
|
|
abstract = False
|
2024-05-06 16:24:16 +02:00
|
|
|
permissions = [("can_see_loan_details", "Can see loan details")]
|
|
|
|
|