class ArchivableModelMixin(BaseModel): """ ArchivableModelMixin Mixin class that provides an `archived` field. This field is used to archive objects instead of deleting them from the database. """ objects = QuerySet.as_manager() archived = fields.BooleanField( default=False, db_index=True, ) class Meta: abstract = True def archive(self): """ Archives the model. """ self.archived = True self.save() def unarchive(self): """ Unarchives the model. """ self.archived = False self.save()
class Product(ProductCommonInfoModel): objects = ProductQuerySet.as_manager() price = fields.FloatField(validators=[MinValueValidator(0)], ) quantity = fields.IntegerField(validators=[MinValueValidator(0)], ) sold_quantity = fields.IntegerField(validators=[MinValueValidator(0)], ) category = fields.ForeignKey( Category, verbose_name='Product category', on_delete=models.SET_NULL, null=True, blank=True, ) gender = fields.ForeignKey( Gender, verbose_name='Product gender', on_delete=models.SET_NULL, null=True, blank=True, ) base_colour = fields.ForeignKey( BaseColour, verbose_name='Product base colour', on_delete=models.SET_NULL, null=True, blank=True, ) season = fields.ForeignKey( Season, verbose_name='Season', on_delete=models.SET_NULL, null=True, blank=True, ) usage = fields.ForeignKey( Usage, verbose_name='Product usage', on_delete=models.SET_NULL, null=True, blank=True, ) article_type = fields.ForeignKey( ArticleType, verbose_name='Article type', on_delete=models.SET_NULL, null=True, blank=True, ) is_published = fields.BooleanField( default=False, help_text='This is a flag which is used to determine that product is' 'published or not. `False`: not published; otherwise, `True`.') def __str__(self): return super().__str__()
class Email(ContributorModel): """ Email model. """ objects = EmailQuerySet.as_manager() email = fields.EmailField() is_verified = fields.BooleanField(default=False, ) def __str__(self): return f'email: {self.email}, verify: {self.is_verified}'
class AddressBook(ContributorModel): """ AddressBook model. """ objects = AddressBookQuerySet.as_manager() customer = fields.ForeignKey( Customer, on_delete=models.CASCADE, ) address = fields.LongNameField() is_default = fields.BooleanField( default=False, help_text='This flag is used to mark which address is default address.', )
class Gift(ContributorModel): """ Gift model """ objects = GiftQuerySet.as_manager() customer = fields.OneToOneField( Customer, on_delete=models.CASCADE, ) is_active = fields.BooleanField( default=True, help_text='This flag is used to determine that customer gift is active' 'or not. `True` is active; otherwise, `False`.') def __str__(self): return f'gift:{self.id}'
class Reward(ContributorModel): """ Reward model """ objects = RewardQuerySet.as_manager() membership = fields.OneToOneField( Membership, on_delete=models.CASCADE, null=True, blank=True, ) is_active = fields.BooleanField( default=True, help_text='A flag for marking that reward is active or not', ) def __str__(self): return f'reward:{self.id}'
class Coupon(ContributorModel): """ Coupon model. """ objects = CouponQuerySet.as_manager() reward = fields.ForeignKey( 'Reward', on_delete=models.CASCADE, help_text='The reward that coupon belong to', ) kind = fields.IntegerField( verbose_name='Coupon kind', choices=CouponKindsEnum.to_tuple(), default=CouponKindsEnum.PERCENTAGE.value, ) code = fields.CharField( verbose_name='Reward unique coupon code', max_length=10, unique=True, ) start_date = models.DateTimeField( verbose_name='Valid date time', null=True, blank=True, ) end_date = models.DateTimeField( verbose_name='Expire date time', null=True, blank=True, ) amount = fields.FloatField( help_text='Depend on coupon kind. If coupon kind is percentage coupon, ' 'its value must be between 0 to 100. If coupon kind is money,' 'its value must be greater than 0', validators=[MinValueValidator(0)], ) target_amount = fields.FloatField( help_text='How much need to be bought to use coupon.', validators=[MinValueValidator(0)], ) is_minimum_purchase = fields.BooleanField( default=True, help_text='This flag is used to determine when customer can use coupon.' '`True`: Coupon can be used when total amount on bill is ' 'greater than or equal `target amount`.' '`False`: Coupon can be used when total amount on bill is' 'less than target amount.', ) is_one_time_using = fields.BooleanField( default=True, help_text='True if coupon is allowed one time using, ' '`False` if it can be used all times.', ) can_by_any_product = fields.BooleanField( default=False, help_text='`True`: coupon can buy any product. ' '`False`: coupon can buy products in the allowed list only.', ) is_active = fields.BooleanField( default=True, help_text='`True` if coupon is active; otherwise, `False`.', ) is_expired = fields.BooleanField( default=False, help_text='`True` if coupon is expired; otherwise, `False`.', ) def __str__(self): return f'coupon:{self.id}' def save(self, **kwargs): if not self.code: self.code = uuid.uuid4() super().save(**kwargs)