Cut out duplicated code between clear_database and populate_db.

(imported from commit 4bb44c20d2f0477d8a3db72788f82b0cf8572b2d)
This commit is contained in:
Tim Abbott
2012-10-29 14:43:00 -04:00
parent 9caf205ed9
commit 6c39bf5cbd
3 changed files with 12 additions and 16 deletions

View File

@@ -1,17 +1,9 @@
from django.core.management.base import NoArgsCommand
from django.contrib.auth.models import User
from zephyr.models import Message, UserProfile, Stream, Recipient, \
Subscription, Huddle, Realm, UserMessage, Client
from django.contrib.sessions.models import Session
from zephyr.models import clear_database
class Command(NoArgsCommand):
help = "Clear only tables we change: messages, accounts + sessions"
def handle_noargs(self, **options):
for model in [Message, Stream, UserProfile, User, Recipient,
Realm, Subscription, Huddle, UserMessage, Client]:
model.objects.all().delete()
Session.objects.all().delete()
clear_database()
self.stdout.write("Successfully cleared the database.\n")