class Product(Model): """Clase que representa un Producto""" name = CharField(max_length=45, help_text='nombre') price = PositiveBigIntegerField(help_text='precio') ingredients = TextField(help_text='ingredientes') preparation = TextField(null=True, blank=True, help_text='preparación') estimated_time = PositiveSmallIntegerField(help_text='tiempo estimado') # Relaciones enterprise = ForeignKey(Enterprise, related_name='products', on_delete=CASCADE, help_text='establecimiento') accompaniments = ManyToManyField('self', blank=True, related_name='products', help_text='acompañamientos') def __str__(self) -> str: """ Función que representa al objeto cuando es recuperado """ return self.name
class UserEarnings(CreatedModified): class TimePeriod(TextChoices): ALL = 'all', _('All') SEVEN_DAYS = '7d', _('7 Days') THIRTY_DAYS = '30d', _('30 Days') uuid = UUIDField(default=uuid.uuid4, editable=False, primary_key=True) user = ForeignKey('users.User', on_delete=CASCADE) repository = ForeignKey(Repository, on_delete=CASCADE) time_period = CharField(max_length=8, choices=TimePeriod.choices) total_amount = PositiveBigIntegerField(validators=[ MaxValueValidator(MAX_POINT_VALUE), MinValueValidator(MIN_POINT_VALUE), ]) class Meta: constraints = [ UniqueConstraint(fields=['repository', 'time_period', 'user'], name='unique_repository_time_period_user') ] default_related_name = 'user_earnings' verbose_name_plural = 'user earnings' def __str__(self): return f'#{self.pk}: {self.user.email}/{self.repository}/{self.time_period}'
class Payment(Model): """Clase que representa un Pago""" payment_type = CharField(max_length=18, choices=PAYMENT_TYPE_CHOICES, help_text='tipo pago') payment_value = PositiveBigIntegerField(help_text='valor pago') # Relaciones delivery = OneToOneField(Delivery, related_name='payment', on_delete=CASCADE, help_text='entrega') def __str__(self) -> str: """ Función que representa al objeto cuando es recuperado """ return self.payment_type
def test_PositiveBigIntegerField(self): lazy_func = lazy(lambda: 1, int) self.assertIsInstance( PositiveBigIntegerField().get_prep_value(lazy_func()), int)