pythondjangoe-commercereferralsdata-caching

Where to store referral code until purchasing somthing in django ecommerce website


I am new to django and I have an ecommerce shop. Now I have added a referral link feature in which after ordering a unique link will be generated and other can come to the website using that link. the referral link url is somthing like this : http://127.0.0.1:8000/orders/referral/qEAKfbOx15n3maHKtgBmhflH1ISPo45q

And the url pattern is :

path('referral/<str:unique_id>/', views.referral, name='referral')

I am redirecting referral user to store page and pass unique id in referral view:

def referral(request, unique_id):
if get_object_or_404(OriginOrder, unique_id=unique_id):
    return redirect(reverse("store") + "?u_id=" + unique_id)

now in store page although I have the unique_id until purchasing something, The user may call a lot of urls like choosing products, search on categories and see the products detail, so in fact I need to store this unique id until purchasing something and then add a reward to the person who sent the referral link to current user. So what is the best option here?

I heard about sessions but I do not know if It is a right option here. I also was thinking about adding a parameter to the cart object of the user called referral code with a null value for default, but the problem is that cart is created once user adds something to his or her cart.So before adding something, he or she may call other urls just to view the products and their details.

does anyone have done the same thing so can help me sharing his experience?


Solution

  • maybe sessions helps you can read more in django docs