def get_last_log(self, file_name=None, finished=False):
        """
        Execute query for the given command most recently started CalAccessCommandLog,
        unless finished=True, in which case query for the most recently finished.

        Commands that require a file / model as a positional argument should
        pass the file_name keyword argument.

        Returns a CalAccessCommandLog object or None, if no results.
        """
        if file_name:
            q = self.command_logs.filter(file_name=file_name)
        else:
            q = self.command_logs

        if finished:
            order_by_field = '-finish_datetime'
            q = q.filter(finish_datetime__isnull=False)
        else:
            order_by_field = '-start_datetime'

        try:
            last_log = q.filter(
                command=self
            ).order_by(order_by_field)[0]
        except __HOLE__:
            last_log = None

        return last_log
dataset/ETHPy150Open california-civic-data-coalition/django-calaccess-raw-data/calaccess_raw/management/commands/__init__.py/CalAccessCommand.get_last_log