feat: add Products form to admin

This commit is contained in:
2026-05-18 17:07:15 +02:00
parent 3b46a18b29
commit 6471b98ec2
9 changed files with 407 additions and 3 deletions

View File

@@ -0,0 +1,45 @@
{% extends "wagtailadmin/base.html" %}
{% load static i18n %}
{% block titletag %}
{% trans "Product" %} {% if product %} — {{ product.name }}{% endif %}
{% endblock titletag %}
{% block content %}
{% include "wagtailadmin/shared/header.html" with title="Products" icon="tag" %}
<div style="padding: 0 3em;">
<a href="{% url 'admin_purchase_dashboard' %}" class="button button-secondary">&larr; {% trans "Back" %}</a>
<h1>{% if product %}{% trans "Edit product" %}{% else %}{% trans "Add product" %}{% endif %}</h1>
{% if error %}
<div class="message error">{{ error }}</div>
{% endif %}
<form action="" method="post">
{% csrf_token %}
<label for="id_name">{% trans "Name" %}</label>
<input id="id_name" name="name" type="text" value="{{ product.name|default_if_none:'' }}" required>
<label for="id_description">{% trans "Description" %}</label>
<textarea id="id_description" name="description">{{ product.description|default_if_none:'' }}</textarea>
<label for="id_price">{% trans "Price (cents)" %}</label>
<input id="id_price" name="price_cents" type="number" value="{{ product.price_cents|default_if_none:'' }}" required>
<label for="id_currency">{% trans "Currency" %}</label>
<input id="id_currency" name="currency" type="text" value="{{ product.currency|default_if_none:'usd' }}">
<p>
{% trans "Stripe product" %}: {{ product.stripe_product_id|default:"—" }}<br>
{% trans "Stripe price" %}: {{ product.stripe_price_id|default:"—" }}
</p>
<div style="margin-top:1em;">
<button type="submit" class="button button-primary">{% trans "Save" %}</button>
{% if product %}
<button type="submit" name="action" value="delete" class="button button-secondary" style="margin-left:0.5em">{% trans "Delete" %}</button>
{% endif %}
</div>
</form>
</div>
{% endblock content %}

View File

@@ -0,0 +1,23 @@
{% extends "wagtailadmin/base.html" %}
{% load static i18n %}
{% block titletag %}
{% trans "Products" %}
{% endblock titletag %}
{% block content %}
{% include "wagtailadmin/shared/header.html" with title="Products" icon="tag" %}
<h1>{% trans "Purchasable Products" %}</h1>
<a href="{% url 'admin_purchase_add' %}" class="button button-primary">{% trans "Add product" %}</a>
<ul>
{% for p in products %}
<li>
<a href="{% url 'admin_purchase' p.id %}">
{{ p.name }} — {{ p.price_cents|floatformat:-2 }} {{ p.currency|upper }}
</a>
</li>
{% empty %}
<li>{% trans "No products found." %}</li>
{% endfor %}
</ul>
{% endblock content %}