如何将查询集从一个视图函数传递到另一个视图函数

时间:2020-01-15 11:53:05

标签: python django

我有一个问题,不知道如何解决。因此,我有一个称为搜索的函数视图,该过滤器使用HTML模板中的用户输入遍历了我的数据库。

def search(request):
 Here I get the input values with the request.GET.get() method from the "homepage/index.html" 
 template and filter throught my databse by the user input 
 (The filter looks like this: qsf = WhiskyContent.objects.all().filter(Q(products__icontains=input) & (Q(volume=volume[0])
                                                                 | Q(volume=volume[1]) | Q(volume=volume[2])
                                                                 | Q(volume=volume[3])) & Q(price__gt=von, price__lt=bis)
                                                                 & Q(concentration__range=(conc, conc_to)))
                        content_order = qsf.order_by("price_with_shipping"))
    return render(request, "homepage/index.html", context)

到目前为止,一切正常,但是现在我需要另一个函数中的已过滤Queryset(content_order),因为我代表了另一个站点上已过滤的数据库项。我在页面index.hmtl上进行过滤,希望这些项目显示在products.html上

因此,我需要函数“产品”中的content_order查询集将值传递给我的html模板“ products.html”

def products(request):

    return render(request, "homepage/products.html")

如果有办法,请告诉我如何:)。另外,如果您有完全不同的想法,请告诉我

0 个答案:

没有答案