med/media/forms.py

34 lines
870 B
Python
Raw Normal View History

2019-08-02 12:57:53 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2017-06-30 01:25:07 +00:00
from django import forms
2019-08-02 12:57:53 +00:00
from django.forms import ModelForm
2019-08-08 19:08:24 +00:00
from .models import Jeu, Emprunt
2019-08-02 12:57:53 +00:00
2017-07-03 16:33:24 +00:00
class JeuForm(ModelForm):
class Meta:
model = Jeu
fields = '__all__'
2017-07-03 23:47:22 +00:00
def clean_nombre_joueurs_max(self):
2019-08-08 19:08:24 +00:00
max_player = self.cleaned_data['nombre_joueurs_max']
if max_player < self.cleaned_data['nombre_joueurs_min']:
2017-07-03 23:47:22 +00:00
raise forms.ValidationError("Max ne peut être inférieur à min")
2019-08-08 19:08:24 +00:00
return max_player
2017-07-03 23:47:22 +00:00
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class EmpruntForm(ModelForm):
class Meta:
model = Emprunt
fields = ['media']
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class EditEmpruntForm(ModelForm):
class Meta:
model = Emprunt
2019-08-08 14:33:05 +00:00
fields = ['media', 'permanencier_emprunt', 'permanencier_rendu',
'date_rendu']