2018-01-30 18:54:01 +00:00
|
|
|
from django.views.generic import ListView, CreateView
|
2018-01-24 10:33:05 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
2018-01-14 12:19:11 +00:00
|
|
|
|
2018-01-24 10:33:05 +00:00
|
|
|
from .models import Content, Category
|
|
|
|
|
|
|
|
|
|
|
|
class ContentCategoryList(ListView):
|
|
|
|
"""Affiche les contenus d'une catégorie."""
|
|
|
|
model = Content
|
|
|
|
context_object_name = "contents"
|
|
|
|
template_name = "content/content_list.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
category_id = self.kwargs['category_id']
|
|
|
|
category = get_object_or_404(Category, id=category_id)
|
|
|
|
return Content.objects.filter(category=category)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(ListView, self).get_context_data(**kwargs)
|
|
|
|
category_id = self.kwargs['category_id']
|
|
|
|
category = get_object_or_404(Category, id=category_id)
|
|
|
|
context['category'] = category
|
|
|
|
return context
|
2018-01-30 18:54:01 +00:00
|
|
|
|
|
|
|
class CreateCategory(CreateView):
|
|
|
|
model = Category
|
|
|
|
fields = '__all__'
|