Use float for price field
This commit is contained in:
parent
651907682c
commit
1c01e4f7dc
2 changed files with 31 additions and 1 deletions
19
manuels/migrations/0023_auto_20180604_1827.py
Normal file
19
manuels/migrations/0023_auto_20180604_1827.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.0.5 on 2018-06-04 16:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import manuels.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('manuels', '0022_teacher_has_confirmed_list'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='book',
|
||||||
|
name='price',
|
||||||
|
field=models.FloatField(validators=[manuels.models.positive_float_validator], verbose_name='prix'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -131,6 +131,17 @@ def isbn_validator(value):
|
||||||
raise ValidationError("%(value)s n'est pas un ISBN valide.", params={'value': value})
|
raise ValidationError("%(value)s n'est pas un ISBN valide.", params={'value': value})
|
||||||
|
|
||||||
|
|
||||||
|
def positive_float_validator(value):
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
except ValueError:
|
||||||
|
raise ValidationError("%(value)s doit être un nombre décimal")
|
||||||
|
|
||||||
|
if value < 0:
|
||||||
|
raise ValidationError("%(value)s doit être un nombre positif")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Book(BaseModel):
|
class Book(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'livre'
|
verbose_name = 'livre'
|
||||||
|
@ -150,7 +161,7 @@ class Book(BaseModel):
|
||||||
"suivis de la lettre <code>X</code>",
|
"suivis de la lettre <code>X</code>",
|
||||||
validators=[isbn_validator]
|
validators=[isbn_validator]
|
||||||
)
|
)
|
||||||
price = models.PositiveIntegerField('prix')
|
price = models.FloatField('prix', validators=[positive_float_validator])
|
||||||
YES_NO_CHOICE = (
|
YES_NO_CHOICE = (
|
||||||
(False, 'Non'),
|
(False, 'Non'),
|
||||||
(True, 'Oui'),
|
(True, 'Oui'),
|
||||||
|
|
Loading…
Reference in a new issue