diff --git a/media/migrations/0006_jeu.py b/media/migrations/0006_jeu.py new file mode 100644 index 0000000..2b5d768 --- /dev/null +++ b/media/migrations/0006_jeu.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-03 14:23 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('media', '0005_auto_20170630_1551'), + ] + + operations = [ + migrations.CreateModel( + name='Jeu', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nom', models.CharField(max_length=255)), + ('duree', models.CharField(choices=[('LONG', 'LONG'), ('MOYEN', 'MOYEN'), ('COURT', 'COURT')], max_length=255)), + ('nombre_joueurs_min', models.IntegerField()), + ('nombre_joueurs_max', models.IntegerField()), + ('comment', models.CharField(blank=True, help_text='Commentaire', max_length=255, null=True)), + ('proprietaire', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/media/models.py b/media/models.py index e52ad29..5cfd7c7 100644 --- a/media/models.py +++ b/media/models.py @@ -13,7 +13,7 @@ class Media(models.Model): # type = TODO def __str__(self): - return str(self.titre) + ' - ' + str(self.auteur) + return str(self.titre) + ' - ' + str(self.auteur.all().first()) class Emprunt(models.Model): media = models.ForeignKey('Media', on_delete=models.PROTECT) @@ -24,6 +24,19 @@ class Emprunt(models.Model): permanencier_rendu = models.ForeignKey('users.User', on_delete=models.PROTECT, related_name='user_permanencier_rendu', blank=True, null=True) +class Jeu(models.Model): + DUREE = ( + ('LONG', 'LONG'), + ('MOYEN', 'MOYEN'), + ('COURT', 'COURT'), + ) + nom = models.CharField(max_length=255) + proprietaire = models.ForeignKey('users.User', on_delete=models.PROTECT) + duree = models.CharField(choices=DUREE, max_length=255) + nombre_joueurs_min = models.IntegerField() + nombre_joueurs_max = models.IntegerField() + comment = models.CharField(help_text="Commentaire", max_length=255, blank=True, null=True) + diff --git a/media/templates/media/aff_emprunts.html b/media/templates/media/aff_emprunts.html index dc9c8cb..aa71fd1 100644 --- a/media/templates/media/aff_emprunts.html +++ b/media/templates/media/aff_emprunts.html @@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} +{% if emprunts_list.paginator %} +{% include "pagination.html" with list=emprunts_list %} +{% endif %} +
{{ media.titre }} | -{{ media.auteur }} | +{% for aut in media.auteur.all %}{{ aut }}, {% endfor %} | {{ media.cote }} | {% include 'buttons/edit.html' with href='media:edit-media' id=media.id %} {% include 'buttons/suppr.html' with href='media:del-media' id=media.id %} diff --git a/media/views.py b/media/views.py index 4fe63c1..9efd126 100644 --- a/media/views.py +++ b/media/views.py @@ -234,6 +234,16 @@ def index(request): emprunts_list = Emprunt.objects.all() else: emprunts_list = Emprunt.objects.filter(user=request.user) + paginator = Paginator(emprunts_list.order_by('date_emprunt').reverse(), PAGINATION_NUMBER) + page = request.GET.get('page') + try: + emprunts_list = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + emprunts_list = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + emprunts_list = paginator.page(paginator.num_pages) return render(request, 'media/index_emprunts.html', {'emprunts_list':emprunts_list}) |