使Tastype味道更好的实用程序。
django-whippedcream的Python项目详细描述
完全对应于django-tastypie。
django WoePid霜提供了一些混合和实用工具。 我的生活更轻松。使用django tastype>;0.12、django>;1.7、python 2.7和>;3.4进行测试
要求
Django Tastypie,当然。如果您想使用DateTimeSerializer,也可以使用Pytz。
安装
- 安装:pip install django-whippedcream
- 将whippedcream添加到INSTALLED_APPS中。
日期时间字段
这是对datetimefield的一个简单添加,它删除毫秒 从战场上。如果您不想提供该级别,这将非常有用 如果你的数据库引擎没有存储这个级别 精确性(mysql)。
from whippedcream.fields import DateTimeField class MyResource(Resource): dt = DateTimeField('dt', normalize=True)
< H3>芘甲拌素< EH3>
此混合类可以添加到任何可能需要的资源中。 在任何常规python代码中访问序列化(json)版本。 它基本上实现了这种模式:
http://django-tastypie.readthedocs.org/en/latest/cookbook.html#using-your-resource-in-regular-views
from whippedcream.mixins import PyAccessMixin class MyResource(MyAccessMixin, Resource): pass # elsewhere... result = MyResource().obj_to_simple(request, obj)