diff --git a/manuels/admin.py b/manuels/admin.py index df61695..88124c5 100644 --- a/manuels/admin.py +++ b/manuels/admin.py @@ -34,9 +34,11 @@ class BookResource(resources.ModelResource): class Meta: model = Book fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor', - 'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field') + 'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field', + 'consumable') export_order = ('level__name', 'field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price', - 'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments') + 'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments', + 'consumable') @admin.register(Book) diff --git a/manuels/forms.py b/manuels/forms.py index 16549ce..f2e417e 100644 --- a/manuels/forms.py +++ b/manuels/forms.py @@ -8,7 +8,7 @@ class EditBookForm(forms.ModelForm): class Meta: model = Book fields = ['teacher', 'level', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'other_editor', - 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments'] + 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'consumable'] no_book = forms.BooleanField(label='Pas de livre pour cette classe/matière', required=False, initial=False) see_later = forms.BooleanField( @@ -24,6 +24,7 @@ class EditBookForm(forms.ModelForm): self.fields['teacher'].widget.attrs.update({'class': 'custom-select'}) self.fields['editor'].widget.attrs.update({'class': 'custom-select'}) self.fields['previously_acquired'].widget.attrs.update({'class': 'custom-select'}) + self.fields['consumable'].widget.attrs.update({'class': 'custom-select'}) if 'level' in self.fields: self.fields['level'].widget.attrs.update({'class': 'custom-select'}) @@ -55,7 +56,7 @@ class EditBookForm(forms.ModelForm): class AddBookForm(EditBookForm): class Meta(EditBookForm.Meta): fields = ['teacher', 'levels', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'other_editor', - 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'add_another'] + 'publication_year', 'isbn', 'price', 'previously_acquired', 'comments', 'add_another', 'consumable'] add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True) levels = forms.ModelMultipleChoiceField( diff --git a/manuels/migrations/0028_auto_20190406_1901.py b/manuels/migrations/0028_auto_20190406_1901.py new file mode 100644 index 0000000..809c119 --- /dev/null +++ b/manuels/migrations/0028_auto_20190406_1901.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2 on 2019-04-06 17:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0027_auto_20190401_2036'), + ] + + operations = [ + migrations.AlterModelOptions( + name='level', + options={'ordering': ['order', 'name'], 'verbose_name': 'classe', 'verbose_name_plural': 'classes'}, + ), + migrations.AddField( + model_name='book', + name='consumable', + field=models.BooleanField(default=False, help_text="Exemple : un cahier d'exercices est un consommable", verbose_name='consommable'), + preserve_default=False, + ), + migrations.AddField( + model_name='level', + name='order', + field=models.IntegerField(default=0, verbose_name='ordre'), + ), + ] diff --git a/manuels/migrations/0029_auto_20190406_1904.py b/manuels/migrations/0029_auto_20190406_1904.py new file mode 100644 index 0000000..a1ce6d9 --- /dev/null +++ b/manuels/migrations/0029_auto_20190406_1904.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-06 17:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0028_auto_20190406_1901'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='consumable', + field=models.BooleanField(choices=[(None, '------------'), (False, 'Non'), (True, 'Oui')], default=None, help_text="Exemple : un cahier d'exercices est un consommable", verbose_name='consommable'), + ), + ] diff --git a/manuels/models.py b/manuels/models.py index 6210ccd..26f14ff 100644 --- a/manuels/models.py +++ b/manuels/models.py @@ -184,6 +184,13 @@ class Book(BaseModel): blank=True, help_text="Ce message sera visible par la documentaliste." ) + consumable = models.BooleanField( + 'consommable', + help_text="Exemple : un cahier d'exercices est un consommable", + choices=YES_NO_CHOICE, + blank=False, + default=None, + ) @property def previously_acquired_text(self): @@ -192,6 +199,13 @@ class Book(BaseModel): else: return 'Non' + @property + def consumable_text(self): + if self.previously_acquired: + return 'Oui' + else: + return 'Non' + def __str__(self): return f'{self.title} ({self.authors}) - {self.isbn}' diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html index 75e5c43..faca794 100644 --- a/manuels/templates/manuels/add_book.html +++ b/manuels/templates/manuels/add_book.html @@ -77,9 +77,12 @@