Django Jquery UI 滑块过滤通过 Ajax

Django Jquery UI Slider Filtering via Ajax

我尝试在 ListView 上制作价格过滤器。当 jquery ui 滑块停止时,过滤器作为 ajax 滑块传递。为了获得结果,我覆盖了 get_queryset() 函数。奇怪的是 get_queryset() 在 ajax 请求后不会给出新结果,即使 get_queryset() 中的 IF 语句执行,因为我可以在安慰。我究竟做错了什么 ? :S

ajax 请求仍然为 Product.objects.all() 结果提供产品,而不是 Product.objects.filter(price=0)

我还尝试将 product_list 作为上下文 ['procuct_list'] 放入 get_context_data() 中,这样它会覆盖 get_queryset() 的结果,但是也没用

!更新! 当我通过地址栏发送获取请求时,url 似乎进行了过滤,但它在 ajax 调用中不起作用??

好像不能只用 ajax 为什么?

class ShopView

class ShopView(ListView):
    model = Product
    template_name = "shop/shop.html"
    context_object_name = "product_list"

def get_context_data(self, **kwargs):
    context = super(ShopView, self).get_context_data(**kwargs)
    context['category_list'] = Category.objects.all()
    return context

def get_queryset(self):
    price = self.request.GET.get('price')
    if price:
        print price #This gets printed
        return Product.objects.filter(price=0) #But this fails!?
    else:
        return Product.objects.all()

JqueryUI滑块

$(function() {
    var priceSlider = ".price-slider";
    var priceMin = "span.min-price";
    var priceMax = "span.max-price";
    $(priceSlider).slider({
        range: "min",
        value:5,
        min: 1,
        max: 5,
        slide: function( event, ui ) {
            $(priceMax).html( ui.value + "€");
        },
        stop: function( event, ui ) {
            var price = ui.value;
            $.ajax({
                type: "GET",
                data: "price=" + price,
                cache: false,
            });
        }
    });

渲染产品的for循环

{% for product in product_list %}
    {% include "shop/product.html" %}
{% endfor %}

产品html本身

<div class="product-price">
    <p>{{ product.price }}€</p>
</div>
...etc

没关系,愚蠢的错误,之后我没有对 AJAX 请求做任何事情。

success: function(data) {
    $("body").html(data);
}