From c0fe3e1db70bdba85cf382624817d8d8ea9d6f85 Mon Sep 17 00:00:00 2001 From: spl3g Date: Mon, 1 Jun 2026 21:23:12 +0300 Subject: add orders list, update, create --- core/models.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'core/models.py') 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): -- cgit v1.2.3