本文介绍了使用唯一的名字查询全名数据存储区属性的最佳过滤器是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Person(db.Model):
person_name = db.StringProperty (required = True)
nacionality = db.StringProperty(required = True)
marital_status = db.StringProperty(required = True)
profession = db.StringProperty(required = True)
SSN = db.IntegerProperty(required = True)
driver_license = db.InteProProperty(required = True)
address = db.PostalAddressProperty(required = True)

在这个模型中,person_name可以是这样的:'Carl Sagan'(只有属性名称的属性)。但是,当我查询它时,这样:

pre $ search $ ='Carl'
p = Person.all()
persons = p.filter('person_name> =',searching_name)

结果,名称不以'Carl'开头,或者在名称的任何部分都没有'Carl'。如果我这样查询: persons = p.filter('person_name> =',searching_name)我没有结果(甚至没有找到'Carl Sagan')。所以,我想知道:这种查询的最佳过滤器是什么? (仅使用第一个名称查询完整的名称属性)?

解决方案

字符串过滤器的工作原理是比较从字符串开始的字符。您可以这样做:

  p.filter('person_name> =',searching_name)
p。 filter('person_name<',searching_name + u'\\\�')


I have this datastore model:

class Person(db.Model):
    person_name = db.StringProperty(required = True)        
    nacionality = db.StringProperty(required = True)
    marital_status = db.StringProperty(required = True)
    profession = db.StringProperty(required = True)
    SSN = db.IntegerProperty(required = True)
    driver_license = db.IntegerProperty(required = True)
    address = db.PostalAddressProperty(required = True)

In this Model, person_name could be something like this: 'Carl Sagan' (there is only on property for the entiry name). But when I query it, this way:

    searched_name = 'Carl'
    p = Person.all()
    persons = p.filter('person_name >=', searched_name)

I got, as a result, names which doesn't begin with 'Carl' or neither have 'Carl' in any part of the name. If I query this way: persons = p.filter('person_name >=', searched_name) I got none result (even 'Carl Sagan' isn't found). So, I'd like to know: what is the best filter to this kind of query? (quering a complete name property using only the first name)?

解决方案

String filter works as it was comparing chars starting beginning of string. You can do something like this:

p.filter('person_name >=', searched_name)
p.filter('person_name <', searched_name + u'\ufffd')

这篇关于使用唯一的名字查询全名数据存储区属性的最佳过滤器是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:26