Created
December 3, 2017 23:39
-
-
Save prokaktus/bd805e3f9a3eabb64be22523ae5fdf66 to your computer and use it in GitHub Desktop.
Workaround for Django-Taggit `KeyError` while calling `similar_objects`
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
# Just example. Feel free to use it and modify to your needs. | |
# ArticlePage - my model | |
# ArticleTag - m2m model for my tags (TaggedItemBase) | |
# taggit_tag - Taggit tag model | |
# (1, 2, 3) - just example tag ids | |
ArticlePage.objects.raw('select a.page_ptr_id, p.title, count(at.tag_id) as tag_count from article_articlepage a join wagtailcore_page p on a.page_ptr_id = p.id join article_articletag at on at.content_object_id = a.page_ptr_id join taggit_tag t on t.id = at.tag_id where tag_id in (1, 2, 3) group by (page_ptr_id, p.id) order by tag_count desc'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment