Add Recette.is_veget boolean
This commit is contained in:
parent
ff4d7a5810
commit
aa3b2fdd7b
|
@ -6,10 +6,13 @@ from .models import Recette
|
||||||
class SearchForm(forms.Form):
|
class SearchForm(forms.Form):
|
||||||
text = forms.CharField(widget=forms.TextInput(attrs={'autofocus': True}))
|
text = forms.CharField(widget=forms.TextInput(attrs={'autofocus': True}))
|
||||||
saison = forms.ChoiceField(choices=(('all', "Toutes"),) + Recette.SAISON_CHOICES)
|
saison = forms.ChoiceField(choices=(('all', "Toutes"),) + Recette.SAISON_CHOICES)
|
||||||
|
veget = forms.BooleanField(label="Végétarien", required=False)
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
if self.is_valid():
|
if self.is_valid():
|
||||||
qs = Recette.objects.all()
|
qs = Recette.objects.all()
|
||||||
|
if self.cleaned_data['veget']:
|
||||||
|
qs = qs.filter(is_veget=True)
|
||||||
if self.cleaned_data['text']:
|
if self.cleaned_data['text']:
|
||||||
qs = qs.filter(nom__icontains=self.cleaned_data['text'])
|
qs = qs.filter(nom__icontains=self.cleaned_data['text'])
|
||||||
if self.cleaned_data['saison'] != 'all':
|
if self.cleaned_data['saison'] != 'all':
|
||||||
|
|
16
recette/migrations/0003_recette_is_veget.py
Normal file
16
recette/migrations/0003_recette_is_veget.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('recette', '0002_recette_saison'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recette',
|
||||||
|
name='is_veget',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='Mets végétarien'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -32,6 +32,7 @@ class Recette(models.Model):
|
||||||
models.CharField(max_length=10, choices=SAISON_CHOICES, blank=True),
|
models.CharField(max_length=10, choices=SAISON_CHOICES, blank=True),
|
||||||
verbose_name="Saison",
|
verbose_name="Saison",
|
||||||
)
|
)
|
||||||
|
is_veget = models.BooleanField("Mets végétarien", default=False)
|
||||||
prep = models.TextField("Préparation", blank=True)
|
prep = models.TextField("Préparation", blank=True)
|
||||||
source = models.CharField("Source", max_length=200, blank=True)
|
source = models.CharField("Source", max_length=200, blank=True)
|
||||||
ingredients = models.ManyToManyField(Ingredient, through='Composition', blank=True)
|
ingredients = models.ManyToManyField(Ingredient, through='Composition', blank=True)
|
||||||
|
|
Loading…
Reference in a new issue