【问题标题】:Create Webapp2 auth user with date property使用 date 属性创建 Webapp2 auth 用户
【发布时间】:2012-11-18 05:55:26
【问题描述】:

我有这个基本模型:

class User(auth_models.User):
username = ndb.StringProperty()
email = ndb.StringProperty()
first_name = ndb.StringProperty()
last_name = ndb.StringProperty()
employee_start_date = ndb.DateProperty()

但是,当我创建用户时:

success, obj = self.auth.store.user_model.create_user(
    "auth:"+ username,
    unique_properties = ['email'],
    email = emailaddress,
    first_name = firstname,
    last_name = lastname,
    employee_start_date = startdate)

我收到以下错误:

NotImplementedError: Property employee_start_date does not support <type 'datetime.date'> types.

(注意:如果我不包含employee_start_date,则创建用户成功)

现在,根据我在互联网上搜索的信息,这是因为 user_model 是一个 expando 模型,并且由于某种原因它不支持日期字段。但是,我不确定。

我也尝试在创建用户后立即添加它,但我收到相同的错误消息:

obj.employee_start_date = startdate
obj.put()

有没有办法给这个用户模型添加一个日期属性?

【问题讨论】:

    标签: google-app-engine authentication date webapp2


    【解决方案1】:

    您尝试分配给employee_start_datestartdate 值不是date 类型,而是datetime。为了让您的代码正常工作,您有两种选择:

    1) 将employee_start_date 更改为datetime

    employee_start_date = ndb.DateTimeProperty()
    

    2) 将startdate 变量设为date 而不是datetime

    【讨论】:

      【解决方案2】:

      要使用您自己的用户类,请确保设置

      config = {'webapp2_extras.auth':{
          'user_model': 'your_auth.User'
      }}
      

      对于 webapp2.WSGIApplication 配置参数

      【讨论】:

        猜你喜欢
        • 2013-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多