From 3c9021f8f45488f320a2b76fa3a412bd91d647b4 Mon Sep 17 00:00:00 2001 From: Med Date: Tue, 4 Jul 2017 01:47:22 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20dur=C3=A9e=20d'un=20jeu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media/forms.py | 5 ++++ media/migrations/0007_auto_20170704_0138.py | 31 +++++++++++++++++++++ media/models.py | 12 ++++---- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 media/migrations/0007_auto_20170704_0138.py diff --git a/media/forms.py b/media/forms.py index 4d8286c..5903892 100644 --- a/media/forms.py +++ b/media/forms.py @@ -39,6 +39,11 @@ class JeuForm(ModelForm): model = Jeu fields = '__all__' + def clean_nombre_joueurs_max(self): + if self.cleaned_data['nombre_joueurs_max'] < self.cleaned_data['nombre_joueurs_min']: + raise forms.ValidationError("Max ne peut être inférieur à min") + return self.cleaned_data['nombre_joueurs_max'] + class EmpruntForm(ModelForm): class Meta: model = Emprunt diff --git a/media/migrations/0007_auto_20170704_0138.py b/media/migrations/0007_auto_20170704_0138.py new file mode 100644 index 0000000..02b7d32 --- /dev/null +++ b/media/migrations/0007_auto_20170704_0138.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-03 23:38 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0006_jeu'), + ] + + operations = [ + migrations.AlterField( + model_name='jeu', + name='duree', + field=models.CharField(choices=[('1h-', '1h-'), ('1-2h', '1-2h'), ('2-3h', '2-3h'), ('4h+', '4h+')], max_length=255), + ), + migrations.AlterField( + model_name='jeu', + name='nombre_joueurs_max', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1)]), + ), + migrations.AlterField( + model_name='jeu', + name='nombre_joueurs_min', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1)]), + ), + ] diff --git a/media/models.py b/media/models.py index 5cfd7c7..5fdd9ec 100644 --- a/media/models.py +++ b/media/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.core.validators import MinValueValidator class Auteur(models.Model): nom = models.CharField(max_length=255) @@ -26,17 +27,18 @@ class Emprunt(models.Model): class Jeu(models.Model): DUREE = ( - ('LONG', 'LONG'), - ('MOYEN', 'MOYEN'), - ('COURT', 'COURT'), + ('-1h', '-1h'), + ('1-2h', '1-2h'), + ('2-3h', '2-3h'), + ('4h+', '4h+'), ) nom = models.CharField(max_length=255) proprietaire = models.ForeignKey('users.User', on_delete=models.PROTECT) duree = models.CharField(choices=DUREE, max_length=255) - nombre_joueurs_min = models.IntegerField() - nombre_joueurs_max = models.IntegerField() + nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)]) + nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)]) comment = models.CharField(help_text="Commentaire", max_length=255, blank=True, null=True)