save value query in views.py

Hi,

I can’t find how save value of my previous query.
I have a filter for my articles (brand, color …) and I would like that when I already clicked on brand and click on color to be able to use the value of my first query for my filter (velo = Velo_stock.objects.filter(Q (pk__in = get_color_velo) | Q (categorie_id = velo)))

my views.py

    velo_ = request.GET.get('category')
velo = Velo.objects.filter(categorie_id=velo_) # value that I want save
get_color = request.GET.get('color')
resultat = 0
print(velo_)
if request.user.is_authenticated:
    user = CartItems.objects.filter(user=request.user)
    nb_article = CartItems.objects.filter(user=request.user).count()
    for cart_line in user:
        cart = cart_line.total()
        resultat = resultat + cart

    if velo_ and get_color:
        velo = Velo_stock.objects.filter(Q(pk__in=get_color_velo) | Q(categorie_id=velo))
        return render(request, 'core/shop.html', {
                    'user1': user,
                    'color': color,
                    'resultat': resultat,
                    'nb_article': nb_article,
                    'category': category,
                    'category2': category2,
                    'velo': velo,
                    'cat': velo_
                    })
    elif get_color:
        get_color_velo = Velo_stock.objects.filter(color_id=get_color).values_list('velo_id')
        velo = velo.filter(pk__in=get_color_velo)
        return render(request, 'core/shop.html', {
                    'user1': user,
                    'color': color,
                    'resultat': resultat,
                    'nb_article': nb_article,
                    'category': category,
                    'category2': category2,
                    'velo': velo,
                    })
    elif velo_:
        velo = Velo.objects.filter(categorie_id=velo_)
        return render(request, 'core/shop.html', {
                'user1': user,
                'color': color,
                'resultat': resultat,
                'nb_article': nb_article,
                'category': category,
                'category2': category2,
                'velo': velo,
                })

You’ve got at least three options for doing this - each with their own side effects.

  1. You can save these in session variables

  2. You can save them in cookies, or in hidden data in forms (if appropriate)

  3. You can render them in your links that you’re generating in your templates. (Add the existing query variables to the url.)