med/media/forms.py

46 lines
1.1 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):
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):
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']
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
fields = ['media', 'permanencier_emprunt', 'permanencier_rendu', 'date_rendu']