Created
June 19, 2012 09:47
-
-
Save smacker/2953300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.cache import cache | |
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
@register.simple_tag() | |
def last_items(num=10): | |
last_items = cache.get('last_items') | |
if not last_items: | |
ads = Ad.objects.filter(status='actual').order_by('-created_date', '-id')[:num] | |
last_items = render_to_string('blocks/inline/last_items.html', {'ads': ads}) | |
cache.set('last_items', last_items) | |
return last_items | |
@receiver(post_save, sender=Ad) | |
def clear_last_items(sender, instance, created, *args, **kwargs): | |
cache.delete('last_items') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment