使用django对一个模型的属性使用多个输入字段 [英] Using multiple input fields for one model's attribute with django

查看:40
本文介绍了使用django对一个模型的属性使用多个输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

models.py 中,我有

class myModel:
    period = models.CharField(max_length = 100, blank=True)

期间应包含以下内容: DD:HH:MM:SS .

在HTML模板中,我希望该字段位于四个不同的文本框输入字段中.有没有办法在Django中做到这一点?

In the HTML template, I want this field to be in four different textbox input fields. Is there a way to do this in 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. Note that there is already a SplitDateTimeField, but that just have two separate fields for each of the date and time.

这篇关于使用django对一个模型的属性使用多个输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆