Summarize data

Please, check my code!
I forgot to include some kind of readme.st. To test custom command:
python manage.py summarize [date YYYY-MM-DD] [--nodeletion]
If you pass no parameters it summarizes current date minus 15 days (single day and no a 15-days period)
This function/method is quite long and I see a lot of oportunities for refactoring and abstraction. Each inner loop is very similar to the parent loop so I would write aux functions/methods to do the hard work. Also, that make them easier to write tests for them.

As this algorithm is actually modifying data (creating new data and removing old data) I think automated tests are pretty important here.