代码之家  ›  专栏  ›  技术社区  ›  cethegeek

模型多重冰场和反转()

  •  0
  • cethegeek  · 技术社区  · 15 年前

    我有一张表格,里面有 ModelMultipleChoiceField .

    我发现自己在做一件事 reverse()

    1 回复  |  直到 15 年前
        1
  •  1
  •   Dan Head    15 年前

    这可能无法百分之百地回答您的问题,但是,我对url中的多值参数使用的技术是将它们作为不透明blob传递给视图,并让视图进行解码。

    # URLConf
    (r'^foo/(?P<ids>([0-9]+,?)+)/)$', foo),
    
    # View
    def foo(request, ids):
        ids=ids.split(',')
    
    # Reverse call
    reverse(foo, ','.join(sorted(ids)))
    

    sorted() 确保ID的等效列表生成相同的URL(假定顺序为 ids 不重要)。你也可以 身份证 set