【问题标题】:TTL with peeweeTTL 与 peewee
【发布时间】:2014-06-13 23:20:05
【问题描述】:

问这个问题我觉得有点奇怪,但经过相当广泛的谷歌搜索后,我真的无法找到答案。

现在我在 PostgresQL 之上使用 peewee ORM,并且我正在实施密码重置。出于显而易见的原因,我不想永远保留密码重置密钥,所以我想在 postgres 中创建对象并让它在设定的时间后过期。

我在文档或 StackOverflow 上找不到任何关于如何执行此操作的信息。这似乎是一个非常常见的用例,但似乎没有关于如何实际执行此操作的任何内容。我的模型供参考:

class PostgresModel(Model):

    _id = PrimaryKeyField()

    class Meta:
        database = DATABASE

    @classmethod
    def create_and_commit(cls, **kwargs):
        cls.create(**kwargs)
        DATABASE.commit()

class ForgotPassword(PostgresModel):
    user = ForeignKeyField(BaseUser, related_name='password_reset')
    secret_key = CharField()

有人对此有见解吗?

【问题讨论】:

    标签: python postgresql peewee ttl


    【解决方案1】:

    在您的模型中添加一个DateTimeField,指示密钥何时到期(或何时创建),然后使用它来确定它是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多