Add paginator et model pour les jeux

This commit is contained in:
Med 2017-07-03 17:48:56 +02:00
parent 760e309afb
commit 2b8ae80b4d
5 changed files with 59 additions and 2 deletions

View File

@ -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)),
],
),
]

View File

@ -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)

View File

@ -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 %}
<table class="table table-striped">
<thead>
<tr>

View File

@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for media in medias_list %}
<tr>
<td>{{ media.titre }}</td>
<td>{{ media.auteur }}</td>
<td>{% for aut in media.auteur.all %}{{ aut }}, {% endfor %}</td>
<td>{{ media.cote }}</td>
<td>{% include 'buttons/edit.html' with href='media:edit-media' id=media.id %}
{% include 'buttons/suppr.html' with href='media:del-media' id=media.id %}

View File

@ -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})