[英]Using multiple input fields for one model's attribute with django
In models.py
I have在models.py
我有
class myModel:
period = models.CharField(max_length = 100, blank=True)
the period
should contain something like: DD:HH:MM:SS
.该period
应包含如下内容: DD:HH:MM:SS
。
In the HTML template, I want this field to be in four different textbox input fields.在 HTML 模板中,我希望此字段位于四个不同的文本框输入字段中。 Is there a way to do this in Django?有没有办法在 Django 中做到这一点?
This is well documented : you need to create a subclass of forms.MultiValueField, which implements a compress
method which returns the combined value of the fields.这是有据可查的:您需要创建 forms.MultiValueField 的子类,它实现了一个compress
方法,该方法返回字段的组合值。 Note that there is already a SplitDateTimeField, but that just have two separate fields for each of the date and time.请注意,已经有一个 SplitDateTimeField,但每个日期和时间只有两个单独的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.