forked from DGNum/gestiojeux
fest(inventory): Improve game image names generation
This commit is contained in:
parent
e050c45530
commit
fe0dc46988
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.core.exceptions import ValidationError
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from autoslug import AutoSlugField
|
||||
from website.validators import MaxFileSizeValidator
|
||||
from comments.models import AbstractComment
|
||||
|
@ -36,6 +39,17 @@ class Tag(models.Model):
|
|||
return reverse("inventory:tag", args=(self.slug,))
|
||||
|
||||
|
||||
def image_uuid_path(instance, filename):
|
||||
"""
|
||||
Compute filename for game images as follow:
|
||||
|
||||
game_img/{random_uuid}.{extension}
|
||||
"""
|
||||
ext = filename.split(".")[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
return os.path.join("uploads/logos", filename)
|
||||
|
||||
|
||||
class Game(models.Model):
|
||||
title = models.CharField(verbose_name="Nom de l'outil", max_length=256, unique=True)
|
||||
slug = AutoSlugField(populate_from="title", unique=True)
|
||||
|
@ -47,7 +61,7 @@ class Game(models.Model):
|
|||
|
||||
description = models.TextField(blank=True, verbose_name="description")
|
||||
image = models.ImageField(
|
||||
upload_to="game_img/",
|
||||
upload_to=image_uuid_path,
|
||||
blank=True,
|
||||
verbose_name="image",
|
||||
help_text="L'image doit peser 512 Kio au maximum",
|
||||
|
|
Loading…
Add table
Reference in a new issue