diff --git a/manuels/admin.py b/manuels/admin.py index 8c38f3f..60c3b32 100644 --- a/manuels/admin.py +++ b/manuels/admin.py @@ -1,3 +1,18 @@ from django.contrib import admin -# Register your models here. +from manuels.models import Teacher, Book, Level + + +@admin.register(Teacher) +class TeacherAdmin(admin.ModelAdmin): + pass + + +@admin.register(Level) +class LevelAdmin(admin.ModelAdmin): + pass + + +@admin.register(Book) +class BookAdmin(admin.ModelAdmin): + pass diff --git a/manuels/forms.py b/manuels/forms.py index d62297a..5d878a2 100644 --- a/manuels/forms.py +++ b/manuels/forms.py @@ -7,3 +7,5 @@ class AddBookForm(forms.ModelForm): class Meta: model = Book fields = '__all__' + + add_another = forms.BooleanField(label='Ajouter un autre livre', required=False) diff --git a/manuels/migrations/0003_auto_20180521_2225.py b/manuels/migrations/0003_auto_20180521_2225.py new file mode 100644 index 0000000..eb0dbbd --- /dev/null +++ b/manuels/migrations/0003_auto_20180521_2225.py @@ -0,0 +1,24 @@ +# Generated by Django 2.0.5 on 2018-05-21 20:25 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0002_auto_20180521_2154'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='level', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Level', verbose_name='classe'), + ), + migrations.AlterField( + model_name='book', + name='teacher', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Teacher', verbose_name='enseignant'), + ), + ] diff --git a/manuels/migrations/0004_auto_20180521_2226.py b/manuels/migrations/0004_auto_20180521_2226.py new file mode 100644 index 0000000..fd14e5e --- /dev/null +++ b/manuels/migrations/0004_auto_20180521_2226.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.5 on 2018-05-21 20:26 + +from django.db import migrations, models +import manuels.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0003_auto_20180521_2225'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='isbn', + field=models.CharField(max_length=20, validators=[manuels.models.isbn_validator], verbose_name='ISBN/EAN'), + ), + ] diff --git a/manuels/migrations/0005_auto_20180521_2230.py b/manuels/migrations/0005_auto_20180521_2230.py new file mode 100644 index 0000000..2d4bf22 --- /dev/null +++ b/manuels/migrations/0005_auto_20180521_2230.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.5 on 2018-05-21 20:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0004_auto_20180521_2226'), + ] + + operations = [ + migrations.AlterModelOptions( + name='level', + options={'verbose_name': 'classe', 'verbose_name_plural': 'classes'}, + ), + ] diff --git a/manuels/migrations/0006_auto_20180521_2307.py b/manuels/migrations/0006_auto_20180521_2307.py new file mode 100644 index 0000000..af37595 --- /dev/null +++ b/manuels/migrations/0006_auto_20180521_2307.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.5 on 2018-05-21 21:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manuels', '0005_auto_20180521_2230'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='previously_acquired', + field=models.BooleanField(choices=[(True, 'Oui'), (False, 'Non')], verbose_name="manuel acquis précédemment par l'élève"), + ), + ] diff --git a/manuels/models.py b/manuels/models.py index 5b99660..a8f5992 100644 --- a/manuels/models.py +++ b/manuels/models.py @@ -20,13 +20,19 @@ class Teacher(models.Model): def full_name(self): return f'{self.first_name} {self.last_name}' + def __str__(self): + return self.full_name + class Level(models.Model): class Meta: verbose_name = 'classe' - verbose_name_plural = 'classe' + verbose_name_plural = 'classes' name = models.CharField('nom', max_length=10) + def __str__(self): + return self.name + def isbn_validator(value): regex = re.compile(r'(\d-?){10,13}X?') @@ -38,14 +44,29 @@ class Book(models.Model): class Meta: verbose_name = 'livre' verbose_name_plural = 'livres' - teacher = models.ForeignKey(to=Teacher, on_delete=models.SET_NULL, null=True) - level = models.ForeignKey(to=Level, on_delete=models.SET_NULL, null=True) + + teacher = models.ForeignKey(verbose_name='enseignant', to=Teacher, on_delete=models.SET_NULL, null=True) + level = models.ForeignKey(verbose_name='classe', to=Level, on_delete=models.SET_NULL, null=True) field = models.CharField('matière', max_length=100) title = models.TextField('titre') authors = models.TextField('auteurs') editor = models.CharField('éditeur', max_length=200) collection = models.CharField('collection', max_length=200, blank=True) publication_year = models.PositiveIntegerField('année de publication') - isbn = models.TextField('ISBN/EAN', validators=[isbn_validator]) + isbn = models.CharField('ISBN/EAN', max_length=20, validators=[isbn_validator]) price = models.PositiveIntegerField('prix') - previously_acquired = models.BooleanField("manuel acquis précédemment par l'élève", blank=True) + YES_NO_CHOICE = ( + (True, 'Oui'), + (False, 'Non'), + ) + previously_acquired = models.BooleanField("manuel acquis précédemment par l'élève", choices=YES_NO_CHOICE, blank=False) + + @property + def previously_acquired_emoji(self): + if self.previously_acquired: + return '✅' + else: + return '🚫' + + 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 232afc1..84a1a3d 100644 --- a/manuels/templates/manuels/add_book.html +++ b/manuels/templates/manuels/add_book.html @@ -2,17 +2,12 @@ {% load bootstrap4 %} -{% block title %}Ajouter un livre{% endblock %} - {% block content %}