使用parseDateTime包将人类可读的日期/时间表达式解析为django字段
django-human-datetime的Python项目详细描述
django人工日期时间分析
Authors: | Justin Quick <justquick@gmail.com> |
---|---|
Version: | 0.1 |
此工具使用parsedatetime package将人类可读的表单输入(如“明晚7点”)转换为datetime对象(如datetime.datetime(2010,4,9,19,…)。 此应用程序需要parsedatetime和pytz。 该应用程序提供了一组字段来替换django自己的datetimefield、datefield和timefield。使用:
from humandt.fields import HumanDateTimeField, HumanTimeField, HumanDateField
然后在您自己的django表单中将它们用作表单字段:
from django.forms import Form class ExampleForm(Form): datetime = HumanDateTimeField(required=False) time = HumanTimeField(required=False) date = HumanDateField(required=False)
示例项目
下载最新的源代码并启动开发服务器。确保您拥有最新版本的django:
git clone git://github.com/justquick/django-human-datetime.git cd django-human-datetime pip install parsedatetime pytz django python setup.py install cd example_project python manage.py runserver
如果一切顺利,它将在http://127.0.0.1:8000/提供。上面有一个示例表单,它只输出解析的日期/时间输入。查看示例“project.views”以获取使用示例。 要测试Humandt应用程序,请停止服务器并运行此程序:
python manage.py test humandt