django condition

def index(request,*args,**kwargs):
    cataloga_obj=Cataloga.objects.all()
    catalogb_obj=Catalogb.objects.all()
    # item_obj=Item.objects.all()
    condition={}
    for k,v in kwargs.items():
        kwargs[k] = int(v)
        if int(v):
            condition[k]=int(v)
    item_obj=Item.objects.filter(**condition)

    print(kwargs)



    return render(request,'index.html',{'cataloga_obj':cataloga_obj,
                                        'catalogb_obj':catalogb_obj,
                                        'item_obj':item_obj,
                                        'kwargs':kwargs,
                                        })
def index(request,*args,**kwargs):
    cataloga_obj=Cataloga.objects.all()
    catalogb_obj=Catalogb.objects.all()
    # item_obj=Item.objects.all()
    condition={}
    for k,v in kwargs.items():
        kwargs[k] = int(v)
        if int(v):
            condition[k]=int(v)
    item_obj=Item.objects.filter(**condition)

    print(kwargs)



    return render(request,'index.html',{'cataloga_obj':cataloga_obj,
                                        'catalogb_obj':catalogb_obj,
                                        'item_obj':item_obj,
                                        'kwargs':kwargs,
                                        })

 

url

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/(?P<cataloga_id>\d+)/(?P<catalogb_id>\d+)', views.index),
]

 

posted @ 2018-04-22 09:14  EngineTang  阅读(103)  评论(0编辑  收藏  举报