我有一个Django表单集与一组初始数据,加载一个外键关系对象到初始形式:Django的FORMSET访问初始数据模板
{{ cellcountformset.management_form }}
{% for form in cellcountformset %}
<div id="">
{{ form.errors }}
{{ form.as_p }}
</div>
{% endfor %}
相关型号是这样的:
class CellType(models.Model):
readable_name = models.CharField(max_length=50)
machine_name = models.CharField(max_length=50)
comment = models.TextField(blank=True)
class CellCount(models.Model):
cell_count_instance = models.ForeignKey(CellCountInstance)
cell = models.ForeignKey(CellType)
normal_count = models.IntegerField()
abnormal_count = models.IntegerField()
comment = models.TextField(blank=True)
我希望能够显示由CellCount模型的单元属性引用的单元的machine_name作为div
的#id
。我使用ModelCormSet作为CellCount,它传递一个CellType对象列表作为其初始数据。
优秀 - 感谢您的! – jvc26