Delete order number in django
I have a list of order numbers. From my service order view, I can manually type in a field number to lookup for a order number to delete. This works well.
order = models.Order.objects.get(pk=1219)
if request.POST.get('delete'):
order.delete()
Now my question. I have an edit order form with a url of /orders/edit/(?P<order_no>\d+)/
, and in this edit order form I can g开发者_StackOverflow中文版o to a new page called /quote/service_order/(?P<client_id>\d+)/(?P<request_type>\d+)/
. In the service order view, this is where an order is deleted. Instead of manually writing down the primary key value (order no), I want to delete the order number that was whatever (?P\d+) was in the edit order form url was before. Is it possible to work a solution to this? I hope I made everything clear.
You can accept multiple parameters from query string, like this:
/quote/service_order/(\d+)/(\d+)
Then in your view:
# client_id - first parameter in braces from the url
# order_id - 2nd parameter in braces from the url
def order_view(request, client_id, order_id):
order = models.Order.objects.get(pk=int(order_id))
if request.POST.get('delete'):
order.delete()
Don't forget to check if user has the permission to delete the order.
精彩评论