我的一个 Wagtail 模型中的 StreamField
中有一个 DateBlock
:
jobs = StreamField([
('job', StructBlock([
('job_title', CharBlock(required=True, max_length=50)),
('job_location', CharBlock(required=True, max_length=50, help_text="City and state")),
('job_description', TextBlock(required=True, min_length=100, max_length=275)),
('link',
URLBlock(required=True, help_text="Provide a link to the job posting")),
('posted_date', DateBlock(required=False, help_text="posted date")),
], verbose_name="BYU job"),),
], blank=True, null=True, verbose_name="Jobs")
有没有办法将 DateBlock
的默认日期设置为当前日期?我还没有在网上找到任何有关如何执行此操作的信息。
最佳答案
在您的 models.py
文件中,您需要导入日期时间,然后在您想要日期字段的类中,您需要添加参数 default=datetime.date.today
希望对您有所帮助。
关于python - 如何将 Wagtail DateBlock 默认设置为当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73364813/