Last active
December 16, 2015 13:39
-
-
Save mikeywaites/5443278 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def get_latest_comments(self, event_ids, limit=3, *args, **kwargs): | |
"""Get the last 3 comments added and re-orders them into ASC | |
order | |
:param event_ids: a list of ints | |
:returns: RawQuerySet | |
""" | |
SQL = """ | |
SELECT * FROM ( | |
SELECT ROW_NUMBER() OVER (PARTITION BY event_id ORDER BY created DESC) | |
AS rank, sub_comment.* FROM feed_actioncomment sub_comment | |
) comment | |
WHERE comment.rank <= %s AND event_id IN (%s) AND is_deleted=false | |
ORDER BY created ASC | |
""" | |
comments = self.raw(SQL, [limit, ','.join(map(str, event_ids))]) | |
return comments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment