Created
March 8, 2013 20:02
-
-
Save shofetim/5119404 to your computer and use it in GitHub Desktop.
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
| from datetime import datetime, timedelta | |
| # If drop is more then 2 years old | |
| two_years_ago = datetime.now() - timedelta(2*365) | |
| drops = DropPoint.objects.filter(created_at__gte=two_years_ago) | |
| for d in drops: | |
| # if it hasn't ordered in the last 2 years mark it as inactive | |
| if d.last_shipable_drop_point_trip > two_years_ago: | |
| d.active = False | |
| d.save() | |
| # if it hasn't placed an order on a route in the last 2 years, | |
| # remote it from that route. | |
| routes = d.route_set.all() | |
| trips = d.routetrip_set.filter(departure__gte=two_years_ago) | |
| route_trips = [i.route for i in trips] | |
| for route in routes: | |
| if route not in route_trips: | |
| d.route_set.remove(route) | |
| d.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment