SUppression de catégories.
This commit is contained in:
parent
549dc91799
commit
6222bf381d
4 changed files with 24 additions and 5 deletions
|
@ -3,6 +3,7 @@ from django.urls import path
|
||||||
from .views import (
|
from .views import (
|
||||||
ContentCategoryList,
|
ContentCategoryList,
|
||||||
CreateCategory,
|
CreateCategory,
|
||||||
|
DeleteCategory,
|
||||||
)
|
)
|
||||||
|
|
||||||
app_name = 'content'
|
app_name = 'content'
|
||||||
|
@ -12,6 +13,11 @@ urlpatterns = [
|
||||||
ContentCategoryList.as_view(),
|
ContentCategoryList.as_view(),
|
||||||
name='category-list'
|
name='category-list'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'category/delete/<int:pk>',
|
||||||
|
DeleteCategory.as_view(),
|
||||||
|
name='category-delete'
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
'category/new/',
|
'category/new/',
|
||||||
CreateCategory.as_view(),
|
CreateCategory.as_view(),
|
||||||
|
|
|
@ -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 django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from .models import Content, Category
|
from .models import Content, Category
|
||||||
|
|
||||||
|
|
||||||
class ContentCategoryList(ListView):
|
class ContentCategoryList(generic.ListView):
|
||||||
"""Affiche les contenus d'une catégorie."""
|
"""Affiche les contenus d'une catégorie."""
|
||||||
model = Content
|
model = Content
|
||||||
context_object_name = "contents"
|
context_object_name = "contents"
|
||||||
|
@ -16,12 +17,17 @@ class ContentCategoryList(ListView):
|
||||||
return Content.objects.filter(category=category)
|
return Content.objects.filter(category=category)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
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_id = self.kwargs['category_id']
|
||||||
category = get_object_or_404(Category, id=category_id)
|
category = get_object_or_404(Category, id=category_id)
|
||||||
context['category'] = category
|
context['category'] = category
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class CreateCategory(CreateView):
|
class CreateCategory(generic.CreateView):
|
||||||
model = Category
|
model = Category
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class DeleteCategory(generic.DeleteView):
|
||||||
|
model = Category
|
||||||
|
success_url = reverse_lazy('settings:index')
|
||||||
|
template_name = "confirm_delete.html"
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<i class="glyphicon glyphicon-edit"></i>
|
<i class="glyphicon glyphicon-edit"></i>
|
||||||
Éditer
|
Éditer
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-danger btn-sm" title="Supprimer" href="">
|
<a class="btn btn-danger btn-sm" title="Supprimer" href="{% url "content:category-delete" c.id %}">
|
||||||
<i class="glyphicon glyphicon-trash"></i>
|
<i class="glyphicon glyphicon-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
7
templates/confirm_delete.html
Normal file
7
templates/confirm_delete.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<form action="" method="post">{% csrf_token %}
|
||||||
|
<p>Êtes-vous certain de vouloir supprimer "{{ object }}"?</p>
|
||||||
|
<input type="submit" value="Confirmer" />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue