forked from DGNum/gestioCOF
Ajoute des filtres sur la page description.
Les variables `GET` `location` et `category` permettent de filtrer sur les salles et catégories dans le résultats de `/bda/descriptions/<id>`
This commit is contained in:
parent
ab4e7ec084
commit
3bca778734
|
@ -16,7 +16,8 @@ class Migration(migrations.Migration):
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', serialize=False,
|
('id', models.AutoField(verbose_name='ID', serialize=False,
|
||||||
auto_created=True, primary_key=True)),
|
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={
|
options={
|
||||||
'verbose_name': 'Cat\xe9gorie',
|
'verbose_name': 'Cat\xe9gorie',
|
||||||
|
@ -25,9 +26,11 @@ class Migration(migrations.Migration):
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Quote',
|
name='Quote',
|
||||||
fields=[
|
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')),
|
('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(
|
migrations.AlterModelOptions(
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Salle(models.Model):
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class CategorieSpectacle(models.Model):
|
class CategorieSpectacle(models.Model):
|
||||||
name = models.CharField('Nom', max_length=300)
|
name = models.CharField('Nom', max_length=100, unique=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
15
bda/views.py
15
bda/views.py
|
@ -10,6 +10,7 @@ from django.db import models
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.forms.models import inlineformset_factory
|
from django.forms.models import inlineformset_factory
|
||||||
|
from django.http import HttpResponseBadRequest
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
@ -368,5 +369,15 @@ def send_rappel(request, spectacle_id):
|
||||||
|
|
||||||
def descriptions_spectacles(request, tirage_id):
|
def descriptions_spectacles(request, tirage_id):
|
||||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||||
shows = tirage.spectacle_set.all()
|
shows_qs = tirage.spectacle_set
|
||||||
return render(request, 'descriptions.html', {'shows': shows})
|
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()})
|
||||||
|
|
Loading…
Reference in a new issue