calculate remaining quota weight - product_id - change role permission serializer

This commit is contained in:
2025-06-28 10:30:48 +03:30
parent 7866e40b1e
commit 2f23c5104d
3 changed files with 16 additions and 1 deletions

View File

@@ -64,10 +64,22 @@ class Product(BaseModel):
null=True
)
def generate_product_id(self): # noqa
""" generate id for product from 10 """
last = Product.objects.filter(product_id__gte=10, product_id__lte=1999).order_by('-product_id').first()
if last:
next_code = last.product_id + 1
else:
next_code = 10
return next_code
def __str__(self):
return f'name: {self.name} - type: {self.type}'
def save(self, *args, **kwargs):
if not self.product_id:
self.product_id = self.generate_product_id() # set product id
super(Product, self).save(*args, **kwargs)