django模型中的星期几表示 [英] django days-of-week representation in model
问题描述
我正在构建此作业服务器"模型.我想添加一个字段,该字段将保存该作业在一周的哪几天进行.最终,在用户界面中,我希望用户能够拥有一系列可以选择的复选框(每天一个).在我的模式下代表这种星期几"数据的最佳方法是什么?
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屋!