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

2024-09-30 20:38:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我遵循的是来自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?

Tags: 函数answertruedbgetreturn指令required