Вот модель:
from django.db import models:
class RefugeCamp(models.Model):
Camp_Name = models.CharField(max_length=100)
Camp_District=models.CharField(max_length=30)
Camp_Address =models.CharField(max_length=200)
Camp_Block = models.IntegerField()
Camp_Population = models.IntegerField()
def __str__(self):
return str(self.Camp_Name)
Вот вид:
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views.generic import ListView
from django.urls import reverse_lazy
from django.db import IntegrityError
from django.views.generic import DetailView,UpdateView,DeleteView
from django.contrib.auth.decorators import login_required
from RefugeCamp.forms import RefugeCampForm
from RefugeCamp.models import RefugeCamp
# Create your views here.
class detail_camp(DetailView):
models=RefugeCampForm
queryset = RefugeCamp.objects.all()
paginate_by = 100
template_name = 'camp/detail.html'
class list_camp(ListView):
models=RefugeCamp
queryset = RefugeCamp.objects.all()
paginate_by = 100
template_name = 'camp/camps.html'
def add_camp_view(request):
if request.method == 'POST':
form = RefugeCampForm(request.POST)
if form.is_valid():
form.save()
pk = form.instance.pk
return redirect('camp:detail.html', pk=pk)
else:
form = RefugeCampForm()
context = {'form': form}
return render(request, 'camp/addcamp.html', context)
class CampDeleteView(DeleteView):
# specify the model you want to use
model = RefugeCamp
template_name = 'camp/delete.html'
# can specify success url
# url to redirect after sucessfully
# deleting object
URL:
from django.urls import path
from .import views
from RefugeCamp.views import list_camp ,detail_camp,CampDeleteView
app_name = 'RefugeCamp'
urlpatterns = [
path('', views.add_camp_view, name='addcamp'),
path('camps/',list_camp.as_view(),name='camps'),
path('detail/<int:pk>/', detail_camp.as_view(), name='detail'),
path('delete/<int:pk>', CampDeleteView.as_view(), name='camp_delete'),
]
теперь я хочу вызвать функцию удаления из лагеря . html
{% extends 'layout.html' %}
{% load crispy_forms_tags %}
{% block content%}
<div class="container">
<div class="row">
<div class="col-4 offset-3">
<h1> Add Refuge Camp </h1>
<form method="POST" >{% csrf_token %}
{{form|crispy}}
<input type="Submit" name="Submit" class="btn btn-primary">
</form>
</div>
</div>
</div>
{% endblock %}
вот страница удаления
<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm">
</form>
я не знаю, как вызвать Camp_DeleteView (DeleteView) из лагеря. html через URL, он отображает все о RefugeCamp и завершении, я хочу отобразить "Удалить". После нажатия кнопки "Удалить" объект должен быть удален