Django商城 訂單管理

訂單管理

Django商城 訂單管理_第1张图片
=我的訂單========Django商城 訂單管理_第2张图片

base.html
 我的订单
urls.py
url(r'^vip/orders$', vip.viporders,name='vip_orders'), #会员中心我的订单
vip.py
def viporders(request):
	context = loadinfo(request)
	odlist = Orders.objects.filter(uid=request.session['vipuser']['id'])
	# 用登錄者ID去查詢訂單Orders() 調取該人的所有訂單訊息(有幾張訂單,訂單號碼多少..etc)
	for od in odlist:
	# 將每筆訂單訊息逐一取出
		dlist = Detail.objects.filter(orderid=od.id)
		# 用訂單號od.id去查詢訂單商品詳情
		for og in dlist:
			# 將每筆訂單商品詳情逐一取出
			og.picname = Goods.objects.only('picname').get(id=og.goodsid).picname
			# 並賦予新屬性picname, 用Detail().goodsid去查詢商品表單Goods().id, 並只取picname為值
		od.detaillist = dlist
		# 賦予新屬性,並指向dlist
	context['orderslist'] = odlist
	context['dlist'] = dlist
	return render(request,"web/viporders.html",context)

*QuerySet is iterable and assignable
while Object is only assignable
to add new data into dict, either use dict.update({new key:new value}) or
dict[0] = {newkey or new dict{newkey:newvalue}}

viporders.html

{% for orders in orderslist %}
订单号:{{ orders.id }}
收货人:{{ orders.linkman }}
收货地址:{{ orders.address }}
联系电话:{{ orders.phone }}
		{% for detail in orders.detaillist %}
			
			
			
			
			{{ detail.name }}
			¥{{ detail.price}}×{{ detail.num}}
		{% endfor %}
¥ {{ orders.total }}  元

		{% if orders.state == 0 %}
		         新订单 


撤销订单】 {% elif orders.state == 1 %} 已发货

确认收货】 {% elif orders.state == 2 %} 已完成 {% elif orders.state == 3 %} 无效订单 {% else %} 未知 {% endif %} {% endfor %}
urls.py
url(r'^vip/odstate$', vip.odstate,name='vip_odstate'), #修改订单状态(确认收货)
vip.py
def odstate(request):
    ''' 修改订单状态 '''
    try:
        oid = request.GET.get("oid",'0')
        ob = Orders.objects.get(id=oid)
        ob.state = request.GET['state']
        ob.save()
        return redirect(reverse('vip_orders'))
    except Exception as err:
        print(err)
        return HttpResponse("订单处理失败!")

你可能感兴趣的:(Django商城 訂單管理)