【问题标题】:Google App Engine GQL Query ORDER BY date_postedGoogle App Engine GQL 查询 ORDER BY date_posted
【发布时间】:2013-10-13 04:29:09
【问题描述】:

我有以下型号:

class Post(db.Model):
    author = db.StringProperty(required=True)
    content = db.StringProperty(required=True)
    date_posted = db.DateTimeProperty()

还有以下 GQL 查询:

db.GqlQuery("SELECT * FROM Post ORDER BY date_posted LIMIT 10")

但帖子仍然以看似随机的顺序显示。我做错了什么?

使用框架:Web.py

【问题讨论】:

    标签: python google-app-engine web.py


    【解决方案1】:

    你没有忘记正确设置 date_posted 吗?或者,也许您希望模型自动分配当前时间?如果是这样,你忘了设置 auto_now_add=True:

    date_posted = db.DateTimeProperty(auto_now_add=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-23
      • 2015-12-22
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      • 2014-03-02
      相关资源
      最近更新 更多