Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Django在表单中生成和提交动态数量的对象_Python_Html_Django_Forms_Web Applications - Fatal编程技术网

Python 使用Django在表单中生成和提交动态数量的对象

Python 使用Django在表单中生成和提交动态数量的对象,python,html,django,forms,web-applications,Python,Html,Django,Forms,Web Applications,我希望能够使用Django在一个表单中更新动态数量的对象,我想知道最好的方法是什么。类似情况的例子可能会有所帮助 型号: class Customer(Model.models): name = models.CharField(max_length=100) active = models.BooleanField() 表单(我知道我在这里混合了视图和模板代码,这不起作用,但这是表单应该做什么的一般概念): customers=Customer.objects.all() 对

我希望能够使用Django在一个表单中更新动态数量的对象,我想知道最好的方法是什么。类似情况的例子可能会有所帮助

型号:

class Customer(Model.models):
    name = models.CharField(max_length=100)
    active = models.BooleanField()
表单(我知道我在这里混合了视图和模板代码,这不起作用,但这是表单应该做什么的一般概念):

customers=Customer.objects.all()
对于c in客户:
打印
  • {c.name}
  • 我将如何提交这些对象的列表?最好的办法是将客户id附加到每个“行”中,然后根据id进行处理吗?是否有提交元组列表的机制?理想的解决方案是什么?


    另外,直接生成的表单模型的等价物是。

    这比我的方法简单得多。谢谢你。
    customers = Customer.objects.all()
    for c in customers:
        print <li> {{ c.name }} <input type="checkbox" value="{{ c.active }}" name="?" />