McDuck/stacking/models.py
2024-08-29 14:21:58 +05:00

51 lines
1.7 KiB
Python

from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from users.models import Balance
class Stake(models.Model):
class StakeEnum(models.TextChoices):
DAY1 = 'DAY1', _('1 день')
WEEK1 = 'WEEK1', _('1 неделя')
WEEK2 = 'WEEK2', _('2 недели')
MONTH1 = 'MONTH1', _('1 месяц')
MONTH3 = 'MONTH3', _('3 месяца')
MONTH6 = 'MONTH6', _('6 месяцев')
YEAR1 = 'YEAR1', _('1 год')
stake_type = models.CharField('Тип', choices=StakeEnum.choices,default=StakeEnum.DAY1, max_length=250)
percent = models.IntegerField('Процент бонусов', null=True, blank=True)
def __str__(self):
return f"{self.stake_type} - {self.percent}%"
class Meta:
verbose_name = 'Stake'
verbose_name_plural = 'Stake'
class UserStake(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
balance = models.ForeignKey(Balance, on_delete=models.CASCADE)
stake = models.ForeignKey(Stake, on_delete=models.CASCADE)
amount = models.DecimalField('Сумма',max_digits=30, decimal_places=4)
is_active = models.BooleanField('Автивен', default=True)
start_date = models.DateTimeField('Время начала', auto_now=True)
def __str__(self):
return f"{self.user.username} - {self.amount} коинов"
class Meta:
verbose_name = 'Пользовательский Stake'
verbose_name_plural = 'Пользовательские Stake'