Is there a way of pulling data.id from the frontend

Viewed 20

The problem comes in at the generation of the str(data.id) to make the unique ID as I'm joining it and the date for record purposes.

#form to return to db

if request.method == 'POST':
    form = OrderForm(request.POST)
    if form.is_valid():
        # store all the billing info
        data = Order()
        data.user = current_user
        data.first_name = form.cleaned_data['first_name']
        data.last_name = form.cleaned_data['last_name']
        data.phone = form.cleaned_data['phone']
        data.email = form.cleaned_data['email']
        data.address_line_1 = form.cleaned_data['address_line_1']
        data.address_line_2 = form.cleaned_data['address_line_2']
        data.country = form.cleaned_data['country']
        data.street = form.cleaned_data['street']
        data.location = form.cleaned_data['location']
        data.county = form.cleaned_data['county']
        data.city = form.cleaned_data['city']
        data.order_note = form.cleaned_data['order_note']
        data.order_total = grand_total
        data.tax = tax
        data.ip = request.META.get('REMOTE_ADDR')
        #data.save()
        # generate order number
        yr = int(datetime.date.today().strftime('%Y'))
        dt = int(datetime.date.today().strftime('%d'))
        mt = int(datetime.date.today().strftime('%m'))
        d = datetime.date(yr, mt, dt)
        current_date = d.strftime("%Y%m%d")
        order_number = current_date + str(data.id)
        data.order_number = order_number
        data.save()

        order=Order.objects.get(user=current_user, is_ordered=False, order_number=order_number)
        context={
            'order':order,
            'cart_items':cart_items,
            'total':total,
            'tax':tax,
            'grand_total':grand_total,
        }
        return render(request,'orders/payments.html', context)
else:
    return redirect('checkout')

#to pull data id

function getCookie(name){ let cookieValue = null; if (document.cookie && document.cookie !== ''){ const cookies = document.cookie.split(';'); for (let i=0; i response.json()) .then((data) => { window.location.href = redirect_url+'?order_number='+data.order_number+'&payment_id='+data.transID; //window.location.href = redirect_url +'?order_number='+data.order_number+'&payment_id='+data.transID; }); } }); } }).render('#paypal-button-container');
0 Answers
Related