Skip to content

Instantly share code, notes, and snippets.

@Suor
Forked from ir4y/view.py
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suor/2644a9707919ef16da43 to your computer and use it in GitHub Desktop.
Save Suor/2644a9707919ef16da43 to your computer and use it in GitHub Desktop.
# Предполагая m2m такого вида
class Tag(model.Model):
text = model.CharField()
class News(models.Model):
tags = models.ManyToManyField(Tag)
def index(request):
# Текущий мастер умеет инвалидировать по событиям на связанных моделях,
# поэтому можно вот так извернуться
@cached_as(News.objects.filter(tags__text__isnull=False))
def _index():
c = {'news': News.objects.all(),
'tags': Tag.objects.all()}
return render("index.html", c)
return _index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment