From 8af63713e47d3822011a80f26ca7acf5890164f7 Mon Sep 17 00:00:00 2001 From: "Gleb O. Ivaniczkij" Date: Sun, 22 Sep 2024 18:05:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9=20=D1=81=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BC,=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=20=D0=BD=D0=B0=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B8=D1=87=D0=BD=D0=BE=D0=BC=20=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models.py b/app/models.py index fe1eac6..32d1cbf 100644 --- a/app/models.py +++ b/app/models.py @@ -1,14 +1,29 @@ +import os + from django.db.models import Model from django.db.models import OneToOneField, ManyToManyField, CASCADE from django.db.models import CharField, TextField, IntegerField, DecimalField, BooleanField, ImageField +def upload_to(path, /): + def wrapper(instance, filename): + return os.path.join( + path, + '%s.%s' % ( + instance.pk, + filename.split('.')[-1], + ), + ) + return wrapper + + class RoomImage(Model): class Meta: verbose_name_plural = 'Изображения комнат' image = ImageField( verbose_name='Изображение', + upload_to=upload_to('media/rooms/images'), ) @@ -18,6 +33,7 @@ class RoomPanorama(Model): image = ImageField( verbose_name='Изображение', + upload_to=upload_to('media/rooms/panoramas'), )