diff --git a/bda/migrations/0007_extends_spectacle.py b/bda/migrations/0007_extends_spectacle.py index 2d6c6fdc..3fa6ccaa 100644 --- a/bda/migrations/0007_extends_spectacle.py +++ b/bda/migrations/0007_extends_spectacle.py @@ -16,7 +16,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('name', models.CharField(max_length=300, verbose_name='Nom')), + ('name', models.CharField(max_length=300, verbose_name='Nom', + unique=True)), ], options={ 'verbose_name': 'Cat\xe9gorie', @@ -25,9 +26,11 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Quote', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('text', models.TextField(verbose_name='Citation')), - ('author', models.CharField(max_length=200, verbose_name='Auteur')), + ('author', models.CharField(max_length=200, + verbose_name='Auteur')), ], ), migrations.AlterModelOptions( diff --git a/bda/models.py b/bda/models.py index 72c7fd3b..8a7d0814 100644 --- a/bda/models.py +++ b/bda/models.py @@ -49,7 +49,7 @@ class Salle(models.Model): @python_2_unicode_compatible class CategorieSpectacle(models.Model): - name = models.CharField('Nom', max_length=300) + name = models.CharField('Nom', max_length=100, unique=True) def __str__(self): return self.name diff --git a/bda/views.py b/bda/views.py index f6c1256a..4ea0df32 100644 --- a/bda/views.py +++ b/bda/views.py @@ -10,6 +10,7 @@ from django.db import models from django.db.models import Count from django.core import serializers from django.forms.models import inlineformset_factory +from django.http import HttpResponseBadRequest import hashlib from django.core.mail import send_mail @@ -368,5 +369,15 @@ def send_rappel(request, spectacle_id): def descriptions_spectacles(request, tirage_id): tirage = get_object_or_404(Tirage, id=tirage_id) - shows = tirage.spectacle_set.all() - return render(request, 'descriptions.html', {'shows': shows}) + shows_qs = tirage.spectacle_set + category_name = request.GET.get('category', '') + location_id = request.GET.get('location', '') + if category_name: + shows_qs = shows_qs.filter(category__name=category_name) + if location_id: + try: + shows_qs = shows_qs.filter(location__id=int(location_id)) + except ValueError: + return HttpResponseBadRequest( + "La variable GET 'location' doit contenir un entier") + return render(request, 'descriptions.html', {'shows': shows_qs.all()})