code: def previous_quarter(d):
      
      from django_toolkit.datetime_util import quarter as datetime_quarter
      return quarter( (datetime_quarter(datetime(d.year, d.month, d.day))[0] + timedelta(days=-1)).date() )
docs: Retrieve the previous quarter for dt