在项目中难免会遇到复杂的条件查询,(1个条件,2个条件,多个条件),想想都头大… 那有没有简单的、灵活的方法呢,答案是True。其实Q对象就可以满足需求,网上也有很多其他的方法,都可以实现,可以一起来看一下我之前写的项目中的案例。
希望有幸帮助到需要的你,欢迎指正~
view.py(后台逻辑代码)
# 店铺商品
def mygoods(request, shop_id):
if request.method == "GET":
try:
# 卖家数量范围区间
seller_volume_from = request.GET.get('seller_volume_from')
seller_volume_to = request.GET.get('seller_volume_to')
# 评论数量范围区间
comment_volume_from = request.GET.get('comment_volume_from')
comment_volume_to = request.GET.get('comment_volume_to')
# 上传时间范围区间
upload_date_from = request.GET.get('upload_date_from')
upload_date_to = request.GET.get('upload_date_to')
# 关键词模糊查询
search_amazon = request