Returning more than one Django data list

1

I made a homepage using django, I'm loading my slides and menus dynamically and it was perfect. I put both the menu and the footer through include and it worked 100%.

Now I came across a problem, the product menu loaded on the main page when I click on it is directed to a specific page of that product, it catches perfectly the product data and everything, the only problem is that loading the products within my menu, even being in the include it loses the data, how do I solve this?

view.py

def list_product(request, template_name='home/index.html'):
    # product = Product.objects.all()
    product = Product.objects.filter(status='True')
    products = {'list_products': product}
    return render(request, template_name, products)

def about_product(request, pk, template_name='home/product.html'):
    about_product = get_object_or_404(Product, pk=pk)
    return render(request, template_name, {'about_product': about_product})
    
asked by anonymous 11.06.2018 / 04:40

1 answer

0

I think a good option would be for you to separate the contexts.

def list_product(request, template_name='home/index.html'):
    menu_all_products = Product.objects.all()
    page_active_products = Product.objects.filter(status='True')
    context = {
        'menu_all_products': menu_all_products,
        'page_active_products', page_active_products,
    }
    return render(request, template_name, context)

From there in your template you will access in the menu the products that should appear there, and in the list page your products that you used in .filter(status='True')

    
13.06.2018 / 16:12