如何在Django中创建一个ic持续时间字段? [英] How to create an ical duration field in Django?

查看:101
本文介绍了如何在Django中创建一个ic持续时间字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在管理站点注册的Django模型。我模型的一个字段代表持续时间。我想使用DateTimeField,但我不想将值保存到数据库中的日期时间,而是想将其保存为varchar(根据RFC5545(标准)格式化)(例如,持续时间为1天1小时1分钟1秒将存储为 P1DT1H1M1S)。我该怎么做?我应该覆盖DateTimeField吗?

I use a Django model that I register with the admin site. One of the fields of my model represents a duration. I would like to use the DateTimeField, but instead of saving the value to a datetime in the database, I would like to save it as varchar, formatted according to RFC5545 (ical) (e.g., a duration of 1 day 1 hour 1 min 1 sec would be stored as "P1DT1H1M1S"). How would I do this? Should I overwrite the DateTimeField?

推荐答案

您可以为其创建一个自定义Django字段,而不是覆盖DateTimeField。

You could create a custom Django field for it instead of overwriting DateTimeField.

https:// docs。 djangoproject.com/en/dev/howto/custom-model-fields/

这篇关于如何在Django中创建一个ic持续时间字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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