Answer the question
In order to leave comments, you need to log in
How to convert ORM query to pure SQL query in Django?
I am newbie. I am doing a study project on Django (online store), the requirements indicate that you cannot use ORM. I have an ORM query that, when placing an order for each item in the cart, assigns its attributes to the OrderItem entity (position in the order). I can't figure out how to pass these product parameters in the cart in raw SQL query. Actually, the ORM request itself looks like this:
for item in cart:
OrderItem.objects.create(order=order,
record=item['record'],
price=item['price'],
quantity=item['quantity'])
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(order=order,
record=item['record'],
price=item['price'],
quantity=item['quantity'])
# очистка корзины
cart.clear()
return render(request, 'orders/order/created.html',
{'order': order})
else:
form = OrderCreateForm
return render(request, 'orders/order/create.html',
{'cart': cart, 'form': form})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question