(self)
Reorder the podcast's episode according to release timestamp

        Returns the highest order value (corresponding to the most recent
        episode)
Reorder the podcast's episode according to release timestamp
Reorder the podcast s episode according to release timestamp
def order_episodes(self):
        """Reorder the podcast's episode according to release timestamp

        Returns the highest order value (corresponding to the most recent
        episode)"""

        num_episodes = self.podcast.episode_count
        if not num_episodes:
            return 0

        episodes = (
            self.podcast.episode_set.all()
            .extra(select={"has_released": "released IS NOT NULL"})
            .order_by("-has_released", "-released", "pk")
            .only("pk")
        )

        for n, episode in enumerate(episodes.iterator(), 1):
            # assign ``order`` from higher (most recent) to 0 (oldest)
            # None means "unknown"
            new_order = num_episodes - n

            # optimize for new episodes that are newer than all existing
            if episode.order == new_order:
                continue

            logger.info("Updating order from {} to {}".format(episode.order, new_order))
            episode.order = new_order
            episode.save()

        self.max_episode_order = num_episodes - 1
def order_episodes ( self ) : num_episodes = self . podcast . episode_count if not num_episodes : return 0 episodes = ( self . podcast . episode_set . all ( ) . extra ( select = { "has_released" : "released IS NOT NULL" } ) . order_by ( "-has_released" , "-released" , "pk" ) . only ( "pk" ) ) for n , episode in enumerate ( episodes . iterator ( ) , 1 ) : # assign ``order`` from higher (most recent) to 0 (oldest) # None means "unknown" new_order = num_episodes - n # optimize for new episodes that are newer than all existing if episode . order == new_order : continue logger . info ( "Updating order from {} to {}" . format ( episode . order , new_order ) ) episode . order = new_order episode . save ( ) self . max_episode_order = num_episodes - 1