from django.db import models from django.urls import reverse from autoslug import AutoSlugField class Category(models.Model): name = models.CharField(max_length=256, verbose_name="nom") slug = AutoSlugField(populate_from="name", unique=True) class Meta: verbose_name = "catégorie" def __str__(self): return self.name def get_absolute_url(self): return reverse("inventory:category", args=(self.slug,)) class Tag(models.Model): name = models.CharField(max_length=256, verbose_name="nom") slug = AutoSlugField(populate_from="name", unique=True) def __str__(self): return self.name def get_absolute_url(self): return reverse("inventory:tag", args=(self.slug,)) class Game(models.Model): title = models.CharField(verbose_name="titre", max_length=256) slug = AutoSlugField(populate_from="title", unique=True) player_range = models.CharField( max_length=256, verbose_name="nombre de joueur·se·s" ) duration = models.CharField(max_length=256, verbose_name="durée de partie") editor = models.CharField(max_length=256, blank=True, verbose_name="éditeur") game_designer = models.CharField( max_length=256, blank=True, verbose_name="game designer" ) description = models.TextField(blank=True, verbose_name="description") category = models.ForeignKey( Category, on_delete=models.RESTRICT, verbose_name="catégorie" ) tags = models.ManyToManyField(Tag, blank=True, verbose_name="tags") image = models.ImageField(upload_to="game_img/", blank=True, verbose_name="image") class Meta: verbose_name = "jeu" verbose_name_plural = "jeux" def __str__(self): return self.title def get_absolute_url(self): return reverse("inventory:game", args=(self.slug,))