-
-
Save Suor/2644a9707919ef16da43 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
# Предполагая 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