Add code to check if there is existing data before executing a bootstrap setup

This commit is contained in:
Roberto Rosario
2012-09-27 01:45:52 -04:00
parent b42a43bafd
commit 3b895d7560
4 changed files with 26 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.db import models
from .exceptions import ExistingData
class Cleanup(object):
"""
@@ -25,6 +29,13 @@ class BootstrapModel(object):
"""
_registry = {}
@classmethod
def check_for_data(cls):
for model in cls.get_all():
model_instance = models.get_model(model.app_name, model.model_name)
if model_instance.objects.all().count():
raise ExistingData
@classmethod
def get_all(cls):
return cls._registry.values()