* validate Promocode.discount to be 0 <= value <= 100
This commit is contained in:
parent
78a187d9c4
commit
8b4f5f9424
19
store/migrations/0034_alter_promocode_discount.py
Normal file
19
store/migrations/0034_alter_promocode_discount.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 4.2.2 on 2023-07-06 21:32
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('store', '0033_remove_user_manager_id'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='promocode',
|
||||||
|
name='discount',
|
||||||
|
field=models.DecimalField(decimal_places=2, max_digits=10, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)], verbose_name='Скидка'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -11,6 +11,7 @@ from django.contrib.admin import display
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager
|
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, Case, When, DecimalField, Prefetch
|
from django.db.models import F, Case, When, DecimalField, Prefetch
|
||||||
from django.db.models.lookups import GreaterThan
|
from django.db.models.lookups import GreaterThan
|
||||||
|
|
@ -135,7 +136,8 @@ class PromocodeQuerySet(models.QuerySet):
|
||||||
|
|
||||||
class Promocode(models.Model):
|
class Promocode(models.Model):
|
||||||
name = models.CharField('Название', max_length=100, unique=True)
|
name = models.CharField('Название', max_length=100, unique=True)
|
||||||
discount = models.DecimalField('Скидка', max_digits=10, decimal_places=2,)
|
discount = models.DecimalField('Скидка', max_digits=10, decimal_places=2,
|
||||||
|
validators=[MinValueValidator(0), MaxValueValidator(100)])
|
||||||
free_delivery = models.BooleanField('Бесплатная доставка', default=False) # freedelivery
|
free_delivery = models.BooleanField('Бесплатная доставка', default=False) # freedelivery
|
||||||
no_comission = models.BooleanField('Без комиссии', default=False) # nocomission
|
no_comission = models.BooleanField('Без комиссии', default=False) # nocomission
|
||||||
is_active = models.BooleanField('Активен', default=True)
|
is_active = models.BooleanField('Активен', default=True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user