为什么过滤后的查询中的.get()返回None?

时间:2011-09-28 16:18:12

标签: python google-app-engine random

我正在遵循answer的指令,为什么我的对象由函数None返回而不是实体?

class FileInfo(db.Model):

    blob = blobstore.BlobReferenceProperty(required=True)
    randomvalue = db.FloatProperty()
    uploaded_by = db.UserProperty()
    facebook_user_id = db.StringProperty()
    uploaded_at = db.DateTimeProperty(required=True, auto_now_add=True)
    category = db.CategoryProperty(choices=('eyes', 'nose', 'mouth',
                                   'other'))

# snip -- shortened here

    def get_random_image(self, category):
    """
        fileinfos = FileInfo.all().filter('category =', category)
        return fileinfos[random.randint(0, fileinfos.count() - 1)]
    """

        q = FileInfo.all()
        q.filter('category =', category)
        q.filter('random >=', random.random())
        return q.get() # why is this not working?

1 个答案:

答案 0 :(得分:3)

q.filter('random >=', random.random())

应更正:

q.filter('randomvalue >=', random.random())