简体   繁体   English

TTL与小矮人

[英]TTL with peewee

I feel a little strange asking this question, but I really have not been able to find an answer after pretty extensive googling. 问这个问题让我有些奇怪,但是经过大量的谷歌搜索之后,我确实没有找到答案。

Right now I'm using the peewee ORM on top of PostgresQL and I'm implementing a password reset. 现在,我在PostgresQL上使用peewee ORM,并且正在实现密码重置。 For obvious reasons I don't want to keep the password-reset keys around forever, so I'd like to create the object in postgres and have it expire after a set amount of time. 由于明显的原因,我不想永远保留密码重置键,因此我想在postgres中创建对象,并让它在设置的时间后过期。

I can't find any mention of how to do this in the docs or on StackOverflow. 我在文档中或StackOverflow上都找不到有关如何执行此操作的内容。 This seems like a pretty common use case, but it seems that there isn't anything out there on how to actually do this. 这似乎是一个很普通的用例,但似乎没有关于如何实际执行此操作的任何信息。 My model for reference: 我的模型供参考:

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()

Anyone have insight on this? 有人对此有见识吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM