如何使用Tastypie基于日期时间字段范围过滤对象。
我有一个帖子模型:
class Post(models.Model):
title = models.CharField(max_length=40)
postTime = models.DateTimeField(auto_now_add=True)
description = models.CharField(max_length=140)
帖子对象通过Tastypie检索。我要检索的对象范围是从今天创建的所有对象到 3 天前创建的所有对象。所以我尝试从查询集中过滤对象,如下所示
RecentPosts(ModelResource):
class Meta:
queryset= Post.objects.filter(postTime__range=(date.today(), date.today() -timedelta(days=3)))
resource_name = 'recent-posts'
fields = ['id','postTime']
authentication = BasicAuthentication()
authorization =DjangoAuthorization()
serializer = Serializer(formats=['json'])
include_resource_uri = False
filtering = {
'postTime': ALL,
'description': ALL,
}
即使这样做了,我也无法检索对象。我还能怎么做呢?