Allow only one discipline per supplies requirement

This commit is contained in:
Gabriel Augendre 2019-04-06 19:26:06 +02:00
parent 62269ec957
commit 900bc53ab8
4 changed files with 39 additions and 4 deletions

View file

@ -70,11 +70,10 @@ class AddBookForm(EditBookForm):
class EditSuppliesForm(forms.ModelForm):
class Meta:
model = SuppliesRequirement
fields = ['teacher', 'level', 'fields', 'supplies']
fields = ['teacher', 'level', 'field', 'supplies']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['fields'].widget.attrs.update(rows=3)
self.fields['supplies'].widget.attrs.update(rows=3)
self.fields['teacher'].widget.attrs.update({'class': 'custom-select'})
if 'level' in self.fields:
@ -83,7 +82,7 @@ class EditSuppliesForm(forms.ModelForm):
class AddSuppliesForm(EditSuppliesForm):
class Meta(EditSuppliesForm.Meta):
fields = ['teacher', 'levels', 'fields', 'supplies']
fields = ['teacher', 'levels', 'field', 'supplies']
add_another = forms.BooleanField(label="Ajouter d'autres fournitures", required=False, initial=True)
levels = forms.ModelMultipleChoiceField(

View file

@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2019-04-06 17:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('manuels', '0030_auto_20190406_1912'),
]
operations = [
migrations.AlterField(
model_name='suppliesrequirement',
name='field',
field=models.CharField(max_length=50, verbose_name='disciplines'),
),
]

View file

@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2019-04-06 17:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('manuels', '0031_auto_20190406_1912'),
]
operations = [
migrations.AlterField(
model_name='suppliesrequirement',
name='field',
field=models.CharField(max_length=50, verbose_name='discipline'),
),
]

View file

@ -223,7 +223,7 @@ class SuppliesRequirement(BaseModel):
teacher = models.ForeignKey(verbose_name='coordonnateur', to=Teacher, on_delete=models.PROTECT, null=True)
level = models.ForeignKey(verbose_name='classe', to=Level, on_delete=models.PROTECT, null=True)
fields = models.TextField('disciplines')
field = models.CharField('discipline', max_length=50)
supplies = models.TextField('fournitures')
done = models.BooleanField(
'Traité',