med/media/forms.py

50 lines
1.3 KiB
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
2017-07-03 16:33:24 +00:00
from .models import Auteur, Media, Jeu, Emprunt
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class AuteurForm(ModelForm):
class Meta:
model = Auteur
fields = '__all__'
2019-08-02 12:57:53 +00:00
2017-06-30 01:25:07 +00:00
class MediaForm(ModelForm):
2019-08-08 14:33:05 +00:00
auteur = forms.ModelMultipleChoiceField(Auteur.objects.all(),
widget=forms.CheckboxSelectMultiple,
required=False)
2017-06-30 01:25:07 +00:00
class Meta:
model = Media
fields = '__all__'
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 14:33:05 +00:00
if self.cleaned_data['nombre_joueurs_max'] < self.cleaned_data[
'nombre_joueurs_min']:
2017-07-03 23:47:22 +00:00
raise forms.ValidationError("Max ne peut être inférieur à min")
return self.cleaned_data['nombre_joueurs_max']
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']