GQL 작동 방식을 이해하지 못해서 발생한 문제가 있습니다. (이것이 첫 번째 날입니다.) Google App Engine (현재 로컬)에서 google.appengine.ext.db 데이터 저장소를 사용하고 있습니다.Google AppEngine for Python의 GQL에서 간단한 데이터 저장/검색
나는 단순히 특정 ID를 가진 사용자를 만든 다음이 ID가있는 레코드 만 포함하도록 필터링하여 검색하려고합니다. 이 작업을 시도해도 아무 것도 반환하지 않지만 모든 작업을 완료하고 반복하여 ID를 비교하면 레코드를 찾습니다. 여기 내가 확실히 보지 못하는 어리석은 실수가 분명히있다. 코드는 다음과 같습니다.
def datastore_key():
return db.Key.from_path('MyUsers', 'all')
class MyUser(db.Model):
my_id = db.TextProperty()
[...]
user = MyUser(parent=datastore_key())
user.my_id = "7wjew1"
user.put()
users = MyUser.all()
users.ancestor(datastore_key())
users.filter("my_id = ", "7wjew1") # WTF - why isn't this working???
print users[0] # is None, users list is empty
# now, let's get all users
users = MyUser.all()
users.ancestor(datastore_key())
# and iterate through the list to check for ids
for user in users:
if user.linkedin_id == user_id:
print "ids are the same"
# surprise, it prints the "ids are the same" - wtf?
OK 가끔 질문을 작성하면 즉시 답변을 얻을 수 있습니다. TextProperty를 StringProperty로 바꿨다. :) – michuk