23. Creating checkout page
def checkout(request):
#! getting the client
if request.user.is_authenticated:
client = request.user.client
else :
if request.COOKIES.get('id_session') :
id_session = request.COOKIES.get("id_session")
client, created = Client.objects.get_or_create(id_session=id_session)
else : #? if the client enters directly on the cart, whithout generating cookies
return redirect('store') #? return directly to the store as the cart should be empty
order, created = Order.objects.get_or_create(client=client, finished=False)
addresses = Adres.objects.filter(client=client) #? filters all adresses associated with the client
context = {"order" : order, "addresses" : addresses}
return render(request, 'checkout.html', context) 



Last updated