(user, limit=10)
return episodes
The last episodes that the user played
The last episodes that the user played
The last episodes that the user played
def last_played_episodes(user, limit=10):
    """The last episodes that the user played"""
    ep_ids = (
        EpisodeHistoryEntry.objects.filter(user=user, action=EpisodeHistoryEntry.PLAY)
        .order_by("episode__id", "-timestamp")
        .distinct("episode__id")
        .values_list("episode__id")
    )
    ep_ids = ep_ids[:limit]
    episodes = (
        Episode.objects.filter(id__in=ep_ids)
        .select_related("podcast")
        .prefetch_related("slugs", "podcast__slugs")
    )
    return episodes
def last_played_episodes ( user , limit = 10 ) : ep_ids = ( EpisodeHistoryEntry . objects . filter ( user = user , action = EpisodeHistoryEntry . PLAY ) . order_by ( "episode__id" , "-timestamp" ) . distinct ( "episode__id" ) . values_list ( "episode__id" ) ) ep_ids = ep_ids [ : limit ] episodes = ( Episode . objects . filter ( id__in = ep_ids ) . select_related ( "podcast" ) . prefetch_related ( "slugs" , "podcast__slugs" ) ) return episodes