让我说我必须排序,它有效,一切都显示,但我不能做分页,事实证明,我绝对所有的商品,分类的项目,事实证明,有200个对象,他们是所有显示,如何使其显示9,即显示9个对象,然后单击下一个链接,然后从排序的类别输出以下产品!?
def sorting_by_ajax(request):
return_dict = {}
data = request.POST
categorys_slug = data.get("category_slug")
category_of_relation_sheps = data.get("category_of_relationsheep")
if len(data.getlist('categoryes[]')) == 0:
categoryes_list = data.get('categoryes')
else:
categoryes_list = data.getlist('categoryes[]')
if len(data.getlist('brands[]')) == 0:
brands_list = data.get("brands")
else:
brands_list = data.getlist('brands[]')
discount_list = data.get("discount_list")
product_himself_list = Product.objects.filter(refers_to__name_of_category__in=categoryes_list, brand__name_of_brand__in=brands_list)
paginator = Paginator(product_himself_list, 9) # Show 25 contacts per page
page = request.GET.get('page')
try:
product_himself = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
product_himself = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
product_himself = paginator.page(paginator.num_pages)
return_dict["products"] = list()
for product in product_himself_list:
new_product = {}
new_product["product_id"] = product.id
new_product["product_brand"] = product.brand.name_of_brand
new_product["product_name"] = product.name_of_product
new_product["product_id"] = product.quantity_of_goods
if product.discount:
new_product["product_price"] = product.price_with_discount
else:
new_product["product_price"] = product.price_of_product
new_product["product_slug"] = product.product_slug
new_product["product_description"] = product.description
new_product["product_image"] = product.poster_image.url
for i in product.size_of_product.all():
if i == 'M':
new_product["product_size_m"] = i
elif i == 'S':
new_product["product_size_s"] = i
elif i == "L":
new_product["product_size_l"] = i
return_dict["products"].append(new_product)
print(product_himself_list)
print(return_dict)
return JsonResponse(return_dict)