【发布时间】:2019-07-03 01:23:02
【问题描述】:
我有一个 django 模型,其中包含一些带有相关选项的字段:
class Product(models.Model):
CONDITION_CHOICES = (
("GOOD", "Good"),
("BAD", "Bad"),
("UNKNOWN", "Unknown"),
)
name = models.CharField(max_length=200, blank=True, null=True)
colour = models.CharField(max_length=200, blank=True, null=True)
condition = models.CharField(max_length=20, choices=CONDITION_CHOICES, blank=True, null=True)
condition_source = models.CharField(max_length=20, blank=True, null=True)
condition_last_updated = models.DateTimeField(blank=True, null=True)
我还有一个引导驱动的表单,如下所示:
<div class="form-group">
<label class="control-label"><strong>Condition</strong></label>
<br/>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-primary">
<input type="radio" name="condition" value="GOOD" autocomplete="off">
Good
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="condition" value="BAD" autocomplete="off">
Bad
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="condition" value="UNKNOWN" autocomplete="off">
Unknown
</label>
</div>
</div>
我试图做到这一点,以便当用户单击 UI 中的一个按钮时,更新 Product 模型(特别是 condition、condition_source 和 condition_last_updated 字段)。实际模型有多个与选择选项相关联的字段,因此我希望模型能够实时更新,而无需在用户处理表单时重新加载页面。
任何指导都将不胜感激 - 我查看了 intercooler.js,但不确定这是否是适合这项工作的工具。
【问题讨论】:
标签: json ajax django twitter-bootstrap bootstrap-4