Add consumable notion for books
This commit is contained in:
parent
ff2df691e7
commit
fd8af82a71
7 changed files with 78 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
28
manuels/migrations/0028_auto_20190406_1901.py
Normal file
28
manuels/migrations/0028_auto_20190406_1901.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
18
manuels/migrations/0029_auto_20190406_1904.py
Normal file
18
manuels/migrations/0029_auto_20190406_1904.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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}'
|
||||
|
||||
|
|
|
@ -77,9 +77,12 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col-12">
|
||||
<div class="col-lg-6 col-12">
|
||||
{% bootstrap_field form.previously_acquired %}
|
||||
</div>
|
||||
<div class="col-lg-6 col-12">
|
||||
{% bootstrap_field form.consumable %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col-12">
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
<th scope="col">ISBN</th>
|
||||
<th scope="col">Prix</th>
|
||||
<th scope="col">Déjà acheté par l'élève</th>
|
||||
<th scope="col">Consommable</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -85,6 +86,10 @@
|
|||
<i class="fas fa-{% if book.previously_acquired %}check-circle{% else %}ban{% endif %}"></i>
|
||||
{{ book.previously_acquired_text }}
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-{% if book.consumable %}check-circle{% else %}ban{% endif %}"></i>
|
||||
{{ book.consumable_text }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -110,7 +115,7 @@
|
|||
<th scope="col">Modifier</th>
|
||||
{% endif %}
|
||||
<th scope="col">Classe</th>
|
||||
<th scope="col">Disciplines</th>
|
||||
<th scope="col">Discipline</th>
|
||||
<th scope="col">Liste de fournitures</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -130,7 +135,7 @@
|
|||
</th>
|
||||
{% endif %}
|
||||
<td>{{ supply.level }}</td>
|
||||
<td>{{ supply.fields }}</td>
|
||||
<td>{{ supply.field }}</td>
|
||||
<td>{{ supply.supplies|linebreaksbr }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue