clear_rooms.py 547 Bytes
Newer Older
Daniel W Bond's avatar
pep8 me  
Daniel W Bond committed
1 2 3
from django.core.management.base import BaseCommand
from accounts.models import Student

4 5 6 7

class Command(BaseCommand):
    args = ""
    help = "Deletes all students' rooms at the end of the semester"
Daniel W Bond's avatar
pep8 me  
Daniel W Bond committed
8

9 10 11
    def handle(self, *args, **kwargs):
        count = 0
        for student in Student.objects.all():
12
            self.stdout.write("Removing %s from %s." % (student, student.room))
13
            student.room = None
14
            student.save()
Daniel W Bond's avatar
pep8 me  
Daniel W Bond committed
15
            count += 1
Briana N Abraham's avatar
Briana N Abraham committed
16

17
        self.stdout.write("Successfully overwrote %d student room(s)." % count)