I'm trying to build a small BBS-like app in Django, and I want to be able to restrict users from deleting posts more than 30 minutes old. However, I can't get the datetime comparison to work in the template engine.
Here is a snippet of my views:
context = {
...
"message_time" : datetime.utcnow() + relativedelta(minutes=-30)
}
And here is the django template in the html:
{% if request.session.userid == post.user.id and post.created_at >= message_time %}
<form action="/wall/message/{{ post.id }}/delete" method="POST">
{% csrf_token %}
<button type="submit">Delete</button>
</form>
{% endif %}
For some reason, the delete button doesn't appear with this snippet, however it works without it (i.e. the message id/session id functionality is fine). I've tried using different combos of relativedelta +/- 30 minutes, created_at greater/less than message_time, but nothing seems to work.