Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created July 20, 2020 17:21
Show Gist options
  • Save bbelderbos/41aa5690bd76510a439e0a7a5fee7fcd to your computer and use it in GitHub Desktop.
Save bbelderbos/41aa5690bd76510a439e0a7a5fee7fcd to your computer and use it in GitHub Desktop.
@register.filter
def is_new(added, days=7):
days_new_deadline = timezone.now() - timezone.timedelta(days=days)
return added > days_new_deadline
# use in template
<a {% with obj.added|is_new as is_new %}
{% if is_new %}class="is_new newLeft"{% endif %}
{% endwith %} href="{% url 'app:view' pk %}">link</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment