From a691a0d0b492155b81319f962f787011e51d0c86 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Wed, 9 Nov 2016 14:34:55 +0100 Subject: [PATCH] add comment to orders --- .../migrations/0032_order_customer_comment.py | 20 +++++++++++++++++++ shop/models.py | 7 +++++++ shop/templates/order_detail.html | 4 +++- shop/views.py | 3 +++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 shop/migrations/0032_order_customer_comment.py diff --git a/shop/migrations/0032_order_customer_comment.py b/shop/migrations/0032_order_customer_comment.py new file mode 100644 index 00000000..a165244d --- /dev/null +++ b/shop/migrations/0032_order_customer_comment.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-09 11:46 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0031_auto_20161109_1000'), + ] + + operations = [ + migrations.AddField( + model_name='order', + name='customer_comment', + field=models.TextField(default=b'', help_text='If you have any comments about the order please enter them here.', verbose_name='Customer comment'), + ), + ] diff --git a/shop/models.py b/shop/models.py index c78712fc..56f56bd9 100644 --- a/shop/models.py +++ b/shop/models.py @@ -117,6 +117,13 @@ class Order(CreatedUpdatedModel): default=False, ) + customer_comment = models.TextField( + verbose_name=_('Customer comment'), + help_text=_('If you have any comments about the order please enter them here.'), + default='', + ) + + objects = OrderQuerySet.as_manager() def __unicode__(self): diff --git a/shop/templates/order_detail.html b/shop/templates/order_detail.html index ed01525a..0a223a05 100644 --- a/shop/templates/order_detail.html +++ b/shop/templates/order_detail.html @@ -38,7 +38,6 @@ name="{{ order_product.id }}" value="{{ order_product.quantity }}" /> {% bootstrap_button '' button_type="submit" button_class="btn-danger" name="remove_product" value=order_product.pk %} - {% else %} {{ order_product.quantity }} {% endif %} @@ -65,6 +64,9 @@ +

Comment:

+

+ {% if not order.open == None %} {% bootstrap_button "Update order" button_type="submit" button_class="btn-primary" name="update_order" %} {% endif %} diff --git a/shop/views.py b/shop/views.py index a328d8a7..89daf2b4 100644 --- a/shop/views.py +++ b/shop/views.py @@ -299,6 +299,7 @@ class OrderDetailView( # Set payment method and mark the order as closed order.payment_method = payment_method order.open = None + order.customer_comment = request.POST.get('customer_comment') order.save() reverses = { @@ -329,6 +330,8 @@ class OrderDetailView( new_quantity = int(request.POST.get(order_product_id)) order_product.quantity = new_quantity order_product.save() + order.customer_comment = request.POST.get('customer_comment') + order.save() product_remove = request.POST.get('remove_product') if product_remove: