summaryrefslogtreecommitdiff
path: root/core/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/models.py')
-rw-r--r--core/models.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/core/models.py b/core/models.py
index db8b4c1..ee673ff 100644
--- a/core/models.py
+++ b/core/models.py
@@ -1,5 +1,10 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
+from PIL import Image
+from io import BytesIO
+from django.core.files.base import ContentFile
+import os
+
class Role(models.Model):
name = models.CharField(max_length=50, unique=True, verbose_name="Name of the role")
@@ -43,8 +48,23 @@ class Product(models.Model):
this = Product.objects.get(id=self.id)
if this.photo and self.photo and this.photo != self.photo:
this.photo.delete(save=False)
+
except Exception:
pass
+
+ if self.photo:
+ img = Image.open(self.photo)
+ img.thumbnail((300, 200))
+
+ output = BytesIO()
+ img.save(output, img.format)
+ output.seek(0)
+ self.photo.save(
+ os.path.basename(self.photo.name),
+ output,
+ save=False
+ )
+
super().save(*args, **kwargs)
@property
@@ -56,12 +76,17 @@ class Product(models.Model):
return self.name
class Order(models.Model):
+ STATUS_CHOICES = (
+ ("new", "Новый"),
+ ("completed", "Завершен"),
+ )
+
order_date = models.DateTimeField(auto_now_add=True)
delivery_date = models.DateTimeField()
pickup_point = models.ForeignKey(PickupPoint, on_delete=models.CASCADE)
client_name = models.CharField(max_length=255, null=True, blank=True)
pickup_code = models.IntegerField()
- status = models.CharField(max_length=50, default="Новый")
+ status = models.CharField(max_length=50, choices=STATUS_CHOICES, default="Новый")
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
class OrderItem(models.Model):