来自here,
我做了这样的testmodel:
class TestModel(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
我制作了一个像这样的HTML代码:
<p>It's made {{ user.testmodel.created|timesince }} ago</p>
<!-- and here is what I ask-->
<p>{% if user.testmodel.created|timesince > 72hours %}Too long time ago{% endif %}</p>
<!-- How can I do this part? -->
我想在django模板上比较timedelta between now and testmodel.created
和72 hours
。
有没有什么好方法可以在django模板标签上执行此操作?