From 654ff5814f58d29c57b06ae0b6b75f2ab7451fbe Mon Sep 17 00:00:00 2001 From: mcbloch Date: Mon, 17 May 2021 21:31:43 +0200 Subject: [PATCH] Add state to order, more info in overview --- mordor/admin.py | 12 ++++++++++++ mordor/migrations/0001_initial.py | 4 +++- mordor/models.py | 10 +++++++++- mordor/templates/mordor/orders.html | 19 ++++++++++++++++++- mordor/templates/mordor/winkel.html | 3 +++ static/main.css | 4 ++-- 6 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 mordor/admin.py diff --git a/mordor/admin.py b/mordor/admin.py new file mode 100644 index 0000000..4385407 --- /dev/null +++ b/mordor/admin.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + + +from django.contrib import admin +from mordor.models import Order + + +class OrderAdmin(admin.ModelAdmin): + model = Order + + +admin.site.register(Order, OrderAdmin) diff --git a/mordor/migrations/0001_initial.py b/mordor/migrations/0001_initial.py index b0d889e..8032191 100644 --- a/mordor/migrations/0001_initial.py +++ b/mordor/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2 on 2021-05-17 18:41 +# Generated by Django 3.2 on 2021-05-17 19:31 from django.conf import settings from django.db import migrations, models @@ -22,6 +22,8 @@ class Migration(migrations.Migration): ('updated_at', models.DateTimeField(auto_now=True)), ('amount_33', models.IntegerField(blank=True, default=0)), ('amount_50', models.IntegerField(blank=True, default=0)), + ('state', models.IntegerField(choices=[(0, 'open'), (1, 'besteld'), (2, 'geleverd')], default=0)), + ('paid', models.BooleanField(default=False)), ('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ diff --git a/mordor/models.py b/mordor/models.py index 044e50a..e3f6cee 100644 --- a/mordor/models.py +++ b/mordor/models.py @@ -11,9 +11,17 @@ class TimeStampMixin(models.Model): class Order(TimeStampMixin): + OPEN, ORDERED, DELIVERED = range(3) + ORDER_STATES = {OPEN: "open", ORDERED: "besteld", DELIVERED: "geleverd"} + amount_33 = models.IntegerField(default=0, blank=True) amount_50 = models.IntegerField(default=0, blank=True) user = models.ForeignKey(CustomUser, null=True, on_delete=models.SET_NULL) + state = models.IntegerField(choices=ORDER_STATES.items(), default=OPEN) + paid = models.BooleanField(default=False) + + def state_str(self): + return self.ORDER_STATES[self.state] def price_33(self): return self.amount_33 * 25 @@ -31,4 +39,4 @@ class Order(TimeStampMixin): self.amount_50 = 0 def __str__(self): - return f"Order {self.amount_33}x33cl, {self.amount_50}x50cl" + return f"Order {self.amount_33}x33cl, {self.amount_50}x50cl for {self.user.username} [{self.state_str()}]" diff --git a/mordor/templates/mordor/orders.html b/mordor/templates/mordor/orders.html index 7bd7de8..007a673 100644 --- a/mordor/templates/mordor/orders.html +++ b/mordor/templates/mordor/orders.html @@ -5,6 +5,12 @@ {% block content %}
{% if orders %} + Bestel datum + Aantal + Bedrag + Status + Betaald + {% for order in orders %}
{{ order.created_at.date }} @@ -14,7 +20,18 @@
{{ order.amount_50 }}x 50cl = €{{ order.price_50 }}
- € {{ order.total_price }}
+ € {{ order.total_price }} + +
+ {{ order.state_str }} +
+
+ {% if order.paid %} + ✓ + {% else %} + ✗ + {% endif %} +
{% csrf_token %} diff --git a/mordor/templates/mordor/winkel.html b/mordor/templates/mordor/winkel.html index 09c5b13..a6ae33a 100644 --- a/mordor/templates/mordor/winkel.html +++ b/mordor/templates/mordor/winkel.html @@ -67,4 +67,7 @@ 0
+
+

Bakken met telkens 20 flesjes

+
{% endblock %} diff --git a/static/main.css b/static/main.css index bd7d731..06e8ab1 100644 --- a/static/main.css +++ b/static/main.css @@ -91,8 +91,8 @@ button { margin: 3em auto 0; font-weight: 400; display: grid; - max-width: 30em; - grid-template-columns: auto 30% 20% auto; + max-width: 40em; + grid-template-columns: auto 30% 20% 20% 10% auto; row-gap: 2em; font-size: 125%; }