|
|
|
@ -1,10 +1,11 @@ |
|
|
|
from django.views.generic import ListView, CreateView |
|
|
|
from django.views import generic |
|
|
|
from django.urls import reverse, reverse_lazy |
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
|
|
|
|
from .models import Content, Category |
|
|
|
|
|
|
|
|
|
|
|
class ContentCategoryList(ListView): |
|
|
|
class ContentCategoryList(generic.ListView): |
|
|
|
"""Affiche les contenus d'une catégorie.""" |
|
|
|
model = Content |
|
|
|
context_object_name = "contents" |
|
|
|
@ -16,12 +17,17 @@ class ContentCategoryList(ListView): |
|
|
|
return Content.objects.filter(category=category) |
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
context = super(ListView, self).get_context_data(**kwargs) |
|
|
|
context = super(generic.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 |
|
|
|
|
|
|
|
class CreateCategory(CreateView): |
|
|
|
class CreateCategory(generic.CreateView): |
|
|
|
model = Category |
|
|
|
fields = '__all__' |
|
|
|
|
|
|
|
class DeleteCategory(generic.DeleteView): |
|
|
|
model = Category |
|
|
|
success_url = reverse_lazy('settings:index') |
|
|
|
template_name = "confirm_delete.html" |
|
|
|
|