Мне нужно, что бы код выглядел не вот так:
try:
ticker_value_at_start_date = TickerValue.objects.get(date=date, ticker=ticker)
except TickerValue.DoesNotExist:
try:
date = date - timedelta(1)
ticker_value_at_start_date = TickerValue.objects.get(date=date, ticker=ticker)
except TickerValue.DoesNotExist:
try:
date = date - timedelta(2)
ticker_value_at_start_date = TickerValue.objects.get(date=date, ticker=ticker)
except:
date = date - timedelta(3)
ticker_value_at_start_date = TickerValue.objects.get(date=date, ticker=ticker)
а вот так :
count = 1
While not TickerValue.DoesNotExist:
date = date - timedelta(count)
ticker_value_at_start_date = TickerValue.objects.get(date=date, ticker=ticker)
Как реализовать такой цикл?)