Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. class Product(models.Model):
  2.     code = models.CharField(max_length=60, unique=True)
  3.     manufacturer = models.CharField(max_length=30)
  4.     name = models.CharField(max_length=200)
  5.     prod_group = models.CharField(max_length=60)
  6.     type = models.CharField(max_length=30)
  7.     sub_type = models.CharField(max_length=30)
  8.     mark = models.CharField(max_length=3)
  9.  
  10.     def __str__(self):
  11.         return self.code
  12.  
  13.  
  14. class PriceList(models.Model):
  15.     product_code = models.ForeignKey('Product', on_delete=models.CASCADE, related_name="price_lists")
  16.     price_a = models.DecimalField(max_digits=10, decimal_places=2)
  17.     price_b = models.DecimalField(max_digits=10, decimal_places=2)
  18.     price_c = models.DecimalField(max_digits=10, decimal_places=2)
  19.     price_d = models.DecimalField(max_digits=10, decimal_places=2)
  20.  
  21.     def __str__(self):
  22.         return f'{self.product_code}:\n' \
  23.                f'| Cena A: {self.price_a} zł \n' \
  24.                f'| Cena B: {self.price_b} zł \n' \
  25.                f'| Cena C: {self.price_c} zł \n' \
  26.                f'| Cena D: {self.price_d} zł |'
  27.  
  28.  
  29. class ActiveProductList(models.Model):
  30.     product_code = models.ForeignKey('Product', on_delete=models.CASCADE)
  31.     is_active = models.BooleanField(default=False)
  32.  
  33.     def change_activity(self, new_status):
  34.         self.is_active = new_status
  35.         self.save()
  36.  
  37.     def __str__(self):
  38.         return f'{self.product_code} status: ACTIVE' if self.is_active is True \
  39.             else f'{self.product_code} status: INACTIVE'
  40.  
  41.  
  42. class ProductAvailability(models.Model):
  43.     product_code = models.ForeignKey('Product', on_delete=models.CASCADE)
  44.     availability = models.IntegerField()
  45.     not_enough = models.IntegerField()
  46.     unavailable = models.IntegerField()
  47.  
  48.     def availability_info(self):
  49.         if None not in (self.not_enough, self.unavailable):
  50.             if self.availability >= self.not_enough:
  51.                 availability_info = 'Dużo'
  52.             elif self.availability > self.unavailable:
  53.                 availability_info = 'Mało'
  54.             else:
  55.                 availability_info = 'Brak'
  56.             return availability_info
  57.  
  58.     def __str__(self):
  59.         return f'{self.product_code} : {self.availability} sztuk. Stan: {self.availability_info()}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement