My problem is that when my Database is empty I am getting this error
IndexError at / list index out of range
> period = Period.objects.all()
> try:
> period_current = [obj for obj in period if ((obj.is_current)==True)]
> total_payment_period_current_dict = LeasePayment.objects.filter(payment_date__range=[period_current[0].start_date,
> period_current[0].end_date]).aggregate(Sum('amount')) ...
> total_payment_period_current = total_payment_period_current_dict['amount__sum']
> except ValueError:
> raise Http404("Can't perform calculation for total_payment_period_current, check data ")
I hoped I can handle it with exeption to give meaningful error , but it doesn't work. What I can do to give meaningful error . Or ideally to avoid this exception all together in case of empty tables?