create a first working example
This commit is contained in:
parent
cf59bf9323
commit
ba3e40f1c2
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
{% load static %}
|
||||
{% load django_htmx %}
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
{% django_htmx_script %}
|
||||
<div class="container">
|
||||
<a href="{% url 'customers' %}">Home</a> |
|
||||
<a href="{% url 'warranties' %}">Warranties</a> |
|
||||
|
@ -35,6 +34,8 @@
|
|||
{% endblock %}
|
||||
</footer>
|
||||
</div>
|
||||
<script src="{% static 'core/js/htmx.js' %}"></script>
|
||||
{% django_htmx_script %}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
{% if request.user.is_superuser %}
|
||||
<div class="row mb-3">
|
||||
<div class="col">
|
||||
<form action="{% url 'customer_create' %}">
|
||||
<input type="submit" value="Add Customer" class="btn btn-primary">
|
||||
</form>
|
||||
<button hx-get="{% url 'htmx_create_customer' %}" hx-target="#htmx-create-customer" class="btn btn-primary">Add Customer</button>
|
||||
</div>
|
||||
<div class="col" id="htmx-create-customer"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block section_title %}Create Customer{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Save" class="btn btn-primary">
|
||||
<a href="{% url 'customers' %}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -11,4 +11,7 @@ urlpatterns = [
|
|||
name='customer_create'),
|
||||
path('delete/customer/<int:pk>/', views.CustomerDeleteView.as_view(),
|
||||
name='customer_delete'),
|
||||
path('htmx/create/customer/',
|
||||
views.HtmxCustomerCreateView.as_view(),
|
||||
name='htmx_create_customer'),
|
||||
]
|
||||
|
|
|
@ -23,6 +23,18 @@ def customers_table_view(request):
|
|||
{'customers': table})
|
||||
|
||||
|
||||
class HtmxCustomerCreateView(LoginRequiredMixin, CreateView):
|
||||
"""
|
||||
A view to create a customer.
|
||||
"""
|
||||
model = Customer
|
||||
template_name = 'customers/partials/customer_create.html'
|
||||
fields = ['name', 'description']
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('customer', args=(self.object.pk,))
|
||||
|
||||
|
||||
class CustomerDetailView(LoginRequiredMixin,
|
||||
PermissionRequiredMixin,
|
||||
DetailView):
|
||||
|
@ -48,4 +60,3 @@ class CustomerDeleteView(LoginRequiredMixin, DeleteView):
|
|||
|
||||
def get_success_url(self):
|
||||
return reverse('computers', args=(self.object.customer.pk,))
|
||||
|
||||
|
|
Loading…
Reference in New Issue