我是Django的新手,我必须创建包含以下输入的网页:位置、技术和服务。第一个网页应该选择一个位置类型,并在此基础上转到下一个页面,该页面根据位置选择技术。第三个web页面根据前面选择的技术和位置选择服务(这将是两者的交叉点),为此,我必须创建模式,其中每个位置可以有多个技术和服务,这两个技术和服务相互独立,每个技术可以有多个服务。你知道吗
eg: loc1_tech->tech1,tech2
loc2_service->service1,service2,service3
tech1_service->service1,service2
tech_service2->service3,service4,service5
如果我们选择loc1,那么下一个网页显示tech1和tech2,如果我选择tech2,那么第三个网页只显示service3,这是loc1和tech2服务的交集。 我计划创建3个模式-loc\u tech,loc\u services,tech\u services in型号.py. 这是创建模式的有效方法吗?另外,如何找到第三个网页的web服务的交集?你知道吗
使用外键组合型号.py以及中的相关\u name属性视图.py也许能帮你解决问题。你知道吗
你知道吗型号.py应该看起来像:
现在在视图中:
注意:技术和位置将由客户端作为参数发送。他们必须得到你的同意网址.py.
当然,您必须配置网址.py接受参数、技术和位置。另外,你也可以使用
其中,
request.GET.get('location_pk' , None)
中的'location\u pk'由客户端发送。你知道吗编辑:
对于发送到服务器的位置或技术的多个实例,方法会有所不同。正如您所说,我们必须使用filter()而不是get()。你知道吗
为了获得技术
现在,result\u technologies将拥有不同查询集列表,由用户选择的所有位置所带来的查询集组成。如果你把它打印在控制台上,它看起来像
[[<;技术:“str-value”>;,技术:“str-value”>;,技术:“str-value”>;,…],[,技术:“str-value”>;,技术:“str-value”>;,…],…]
即:查询集列表。 现在您将有一个问题,加入querysets获取,因为querysets列表将产生混乱。see here how to join querysets 连接可以简单地做为
希望这有帮助。谢谢。你知道吗
相关问题 更多 >
编程相关推荐