本文整理匯總了Python中orders.models.Order.grandtotal方法的典型用法代碼示例。如果您正苦於以下問題:Python Order.grandtotal方法的具體用法?Python Order.grandtotal怎麽用?Python Order.grandtotal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類orders.models.Order
的用法示例。
在下文中一共展示了Order.grandtotal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: overview
# 需要導入模塊: from orders.models import Order [as 別名]
# 或者: from orders.models.Order import grandtotal [as 別名]
def overview(request):
if request.method == 'POST':
if 'process' in request.POST:
orders = []
for order in Order.objects.all():
orderdict = model_to_dict(order)
orderdict['items'] = [{'name': item.name,
'price': item.real_price(order.date)}
for item in order.items.all()]
orderdict['total'] = order.total()
orders.append(orderdict)
if orders:
receipt = {'grandtotal': Order.grandtotal(),
'orders': orders}
contents = json.dumps(receipt, cls=DateTimeEncoder)
Receipt(contents=contents).save()
Order.objects.all().delete()
messages.success(request, "Alle bestellingen verwerkt!")
elif 'remove' in request.POST:
order = Order.objects.get(pk=request.POST['remove'])
msg = "Bestelling van {.name} verwijderd!".format(order)
order.delete()
messages.success(request, msg)
elif 'slack' in request.POST and hasattr(settings, 'SLACK'):
jsondata = {'text': 'Nieuwe bestelling!',
'channel': settings.SLACK['channel'],
'username': settings.SLACK['username'],
'icon_emoji': settings.SLACK['icon_emoji']}
for order in Order.objects.all():
jsondata['text'] += '\n*{}* ({}):'.format(
order.name, euro(order.total()))
items = [' {} ({})'.format(item.name,
euro(item.real_price(order.date)))
for item in order.items.all()]
jsondata['text'] += ', '.join(items)
payload = {'payload': json.dumps(jsondata)}
data = urllib.parse.urlencode(payload).encode('UTF-8')
req = urllib.request.Request(settings.SLACK['webhook'], data)
urllib.request.urlopen(req)
messages.success(request, "Bestellingen gedeeld via Slack!")
return HttpResponseRedirect(reverse('overview'))
orders = Order.objects.all()
context = {'orders': orders, 'grandtotal': Order.grandtotal(),
'slack': hasattr(settings, 'SLACK')}
return render(request, 'orders/overview.html', context)
示例2: test_grandtotal
# 需要導入模塊: from orders.models import Order [as 別名]
# 或者: from orders.models.Order import grandtotal [as 別名]
def test_grandtotal(self):
order1 = Order.objects.get(name="Test Order 1")
order2 = Order.objects.get(name="Test Order 2")
for item in self.items:
ItemOrder.objects.create(item=item, order=order1)
ItemOrder.objects.create(item=item, order=order2)
order1.save()
order2.save()
self.assertEqual(Order.grandtotal(), 950)