django 模型中的星期几表示 [英] django days-of-week representation in model
问题描述
我正在构建这个Jobs Server"模型.我想包含一个字段,用于保存此作业将在一周中的哪几天运行.最终在 UI 中,我希望用户能够选择一系列复选框(每天一个).在我的模式中表示这些星期几"数据的最佳方式是什么?
I have this "Jobs Server" model that i'm building. I want to include a field that will save which days of the week this job will run on. Ultimately in the UI, i would like the user to be able to have a series of check boxes(one for each day) that they can select. What would be the best way to represent this "days-of-week" data in my mode?
class Job(models.Model):
name = models.CharField(max_length=32, unique=True)
package = models.ForeignKey(Package)
binary = models.ForeignKey(Binary)
host = models.ForeignKey(Host)
colo = models.ForeignKey(Location)
group = models.ForeignKey(Group)
type = models.ForeignKey(Type)
start = models.TimeField()
end = models.TimeField()
days = ?
推荐答案
如果您希望每个复选框都有一个复选框,那么最简单的方法就是为每个复选框创建一个 BooleanFields.如果您想将其存储为更复杂的值(例如逗号分隔列表或其他内容),请创建您自己的小部件并使用 javascript,然后您可以走这条路.
If you want a checkbox for each one, then the easiest thing to do is to create BooleanFields for each of them. If you want to store it as a more complex value (eg. comma separated list or something), create your own widget and play with javascript, then you could go that route.
这篇关于django 模型中的星期几表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!