adding argumement hidden to Article

in order to avoid some articles to appear in the menu
This commit is contained in:
Qwann 2017-01-26 19:22:38 +01:00
parent 3ca38bd8e9
commit aa1afccf1f
4 changed files with 28 additions and 7 deletions

View file

@ -262,12 +262,12 @@ class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ['name', 'is_sold', 'price', 'stock', 'category', 'box_type',
fields = ['name', 'is_sold', 'hidden', 'price', 'stock', 'category', 'box_type',
'box_capacity']
class ArticleRestrictForm(ArticleForm):
class Meta(ArticleForm.Meta):
fields = ['name', 'is_sold', 'price', 'category', 'box_type',
fields = ['name', 'is_sold', 'hidden', 'price', 'category', 'box_type',
'box_capacity']
# -----

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('kfet', '0047_auto_20170104_1528'),
]
operations = [
migrations.AddField(
model_name='article',
name='hidden',
field=models.BooleanField(help_text='Si oui, ne sera pas affiché au public ; par exemple sur la carte.', default=False),
),
]

View file

@ -331,6 +331,10 @@ class ArticleCategory(models.Model):
class Article(models.Model):
name = models.CharField(max_length = 45)
is_sold = models.BooleanField(default = True)
hidden = models.BooleanField(default=False,
help_text="Si oui, ne sera pas affiché "
"au public ; par exemple "
"sur la carte.")
price = models.DecimalField(
max_digits = 6, decimal_places = 2,
default = 0)

View file

@ -48,12 +48,10 @@ class Home(TemplateView):
def get_context_data(self, **kwargs):
context = super(TemplateView, self).get_context_data(**kwargs)
articles = Article.objects.all()
context['pressions'] = (articles.filter(category__name='Pression')
.filter(is_sold=True))
articles = Article.objects.all().filter(is_sold=True, hidden=False)
context['pressions'] = articles.filter(category__name='Pression')
context['articles'] = (articles.exclude(category__name='Pression')
.filter(is_sold=True)
.order_by('category'))
.order_by('category'))
return context
@method_decorator(login_required)