Good practices for a flexible search page - Django

为君一笑 提交于 2019-12-04 21:25:29

Try this:

ALLOWED = ('color', 'size', 'model')
kwargs = dict(
    (key, value)
    for key, value in request.GET.items()
    if key in ALLOWED
)
query.filter(**kwargs)

This will allow you to make requests like this /search/?color=red&size=1 or /search/?model=Nikon&color=black.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!