Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created March 8, 2013 20:02
Show Gist options
  • Select an option

  • Save shofetim/5119404 to your computer and use it in GitHub Desktop.

Select an option

Save shofetim/5119404 to your computer and use it in GitHub Desktop.
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