delete views

This commit is contained in:
vabene1111 2018-03-30 22:52:43 +02:00
parent 37639ad4c7
commit a155c0c522
3 changed files with 26 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import django_tables2 as tables
from django_tables2.utils import A # alias for Accessor
from django.utils.translation import gettext as _
from .models import *
@ -38,7 +39,7 @@ class KeywordTable(tables.Table):
class MonitoredPathTable(tables.Table):
edit = tables.TemplateColumn("<a href='#' >Löschen</a>")
edit = tables.TemplateColumn("<a href='{% url 'delete_monitor' record.id %}' >" + _('Delete') + "</a>")
class Meta:
model = Keyword

View File

@ -17,6 +17,10 @@ urlpatterns = [
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
path('edit/monitor/<int:pk>/', edit.MonitorUpdate.as_view(), name='edit_monitor'),
path('delete/keyword/<int:pk>/', edit.KeywordDelete.as_view(), name='delete_keyword'),
path('delete/category/<int:pk>/', edit.CategoryDelete.as_view(), name='delete_category'),
path('delete/monitor/<int:pk>/', edit.MonitorDelete.as_view(), name='delete_monitor'),
path('batch/import', batch.batch_import, name='batch_import'),
path('batch/category', batch.batch_edit, name='batch_edit'),

View File

@ -4,7 +4,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect, render
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import UpdateView
from django.views.generic import UpdateView, DeleteView
from cookbook.forms import EditRecipeForm
from cookbook.models import Recipe, Category, Monitor, Keyword
@ -48,3 +48,22 @@ def recipe(request, recipe_id):
form = EditRecipeForm(instance=recipe_obj)
return render(request, 'edit/recipe.html', {'form': form})
# Generic Delete views
class MonitorDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Monitor
success_url = reverse_lazy('index')
class CategoryDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Category
success_url = reverse_lazy('index')
class KeywordDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Keyword
success_url = reverse_lazy('index')