mirror of
https://github.com/Crocmagnon/checkout.git
synced 2024-11-22 08:08:04 +01:00
Add delete and list views for baskets
This commit is contained in:
parent
74609d8e04
commit
1784c664ea
4 changed files with 57 additions and 3 deletions
10
src/purchase/templates/purchase/basket_confirm_delete.html
Normal file
10
src/purchase/templates/purchase/basket_confirm_delete.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
{% extends "common/base.html" %}
|
||||
{% block content %}
|
||||
<h1>{{ object }}</h1>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<p>Are you sure you want to delete "{{ object }}"?</p>
|
||||
{{ form }}
|
||||
<input class="btn btn-danger" type="submit" value="Confirm">
|
||||
</form>
|
||||
{% endblock %}
|
22
src/purchase/templates/purchase/basket_list.html
Normal file
22
src/purchase/templates/purchase/basket_list.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
{% extends "common/base.html" %}
|
||||
{% block content %}
|
||||
<h1>Baskets</h1>
|
||||
<div class="row">
|
||||
{% for basket in baskets %}
|
||||
<div class="col-sm-3 mb-3 mt-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Basket #{{ basket.id }}</h5>
|
||||
<p class="card-text">
|
||||
{{ basket.items.count }} items<br>
|
||||
{{ basket.price_display }}<br>
|
||||
{{ basket.payment_method }}
|
||||
</p>
|
||||
<a href="{% url "purchase:update" basket.id %}" class="btn btn-sm btn-primary">Edit</a>
|
||||
<a href="{% url "purchase:delete" basket.id %}" class="btn btn-sm btn-danger">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,9 +1,16 @@
|
|||
from django.urls import path
|
||||
|
||||
from purchase.views import NewBasketView, UpdateBasketView
|
||||
from purchase.views import (
|
||||
DeleteBasketView,
|
||||
ListBasketsView,
|
||||
NewBasketView,
|
||||
UpdateBasketView,
|
||||
)
|
||||
|
||||
app_name = "purchase"
|
||||
urlpatterns = [
|
||||
path("", ListBasketsView.as_view(), name="list"),
|
||||
path("new/", NewBasketView.as_view(), name="new"),
|
||||
path("update/<int:pk>/", UpdateBasketView.as_view(), name="update"),
|
||||
path("<int:pk>/update/", UpdateBasketView.as_view(), name="update"),
|
||||
path("<int:pk>/delete/", DeleteBasketView.as_view(), name="delete"),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from django.urls import reverse
|
||||
from django.views.generic import CreateView, UpdateView
|
||||
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||||
|
||||
from purchase.forms import BasketForm
|
||||
from purchase.models import Basket
|
||||
|
@ -20,3 +20,18 @@ class UpdateBasketView(ProtectedViewsMixin, UpdateView):
|
|||
permission_required = ["purchase.change_basket", "purchase.view_basket"]
|
||||
model = Basket
|
||||
form_class = BasketForm
|
||||
|
||||
|
||||
class ListBasketsView(ProtectedViewsMixin, ListView):
|
||||
permission_required = ["purchase.view_basket"]
|
||||
model = Basket
|
||||
context_object_name = "baskets"
|
||||
ordering = "-id"
|
||||
|
||||
|
||||
class DeleteBasketView(ProtectedViewsMixin, DeleteView):
|
||||
permission_required = ["purchase.delete_basket"]
|
||||
model = Basket
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("purchase:list")
|
||||
|
|
Loading…
Reference in a new issue