from django.utils import timezone from web.models import Event def deactivate(): today = timezone.now() active_events = Event.objects.filter(active=True).all() for event in active_events: if 'BP' in event.name: if event.end_date < today: event.active = False event.save()