3π
β
My god, what was I thinking. This would be the cleanest solution ofcourse:
def product_add_from_history(request, order_id=None, product_id=None):
""" Add existing product to current order
"""
order = get_object_or_404(Order, pk=order_id, owner=request.user)
product = Product.objects.get(owner=request.user, pk=product_id)
newproduct = Product(
owner=request.user,
order = order,
name = product.name,
amount = product.amount,
unit_price = product.unit_price,
)
newproduct.save()
return HttpResponseRedirect(reverse('order-detail', args=[order_id]) )
π€GerardJP
0π
A view is a regular python method, you can of course call one from another giving you pass proper arguments and handle the result correctly (like 404β¦). Now if it is a good practice I donβt know. I would myself to an utiliy method and call it from both views.
π€Nicolas Goy
- [Django]-Get the values of multiple checkboxes in django
- [Django]-Django Class Based Views keep url parameters in session
0π
If you are fine with the overhead of calling your API through HTTP you can use urllib
to post
a request to your product_add
request handler.
As far as I know this could add some troubles if you develop with the dev server that comes with django, as it only handles one request at a time and will block indefinitely (see trac, google groups).
π€tosh
Source:stackexchange.com