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
# I can never remember that this is a thing, but it is occasionally useful for me | |
ids = [5, 2, 3, 1, 4] | |
order = Case(*[When(id=id, then=pos) for pos, id in enumerate(ids)]) | |
queryset = MyModel.objects.filter(id__in=ids).order_by(order) |
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
import logging | |
import time | |
from contextlib import ContextDecorator | |
class log_execution_time(ContextDecorator): | |
""" | |
A context processor and decorator for logging timings. | |
logger = logging.getLogger(__name__) | |
@log_execution_time('my_func', logger, logging.DEBUG) |
OlderNewer