Created
September 7, 2012 06:15
-
-
Save Suor/3663735 to your computer and use it in GitHub Desktop.
django ModelCommand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from django.core.management.base import LabelCommand, CommandError | |
from django.db.models.loading import get_model | |
class ModelCommand(LabelCommand): | |
args = 'model+' | |
def handle_label(self, label, **options): | |
if not re.search(r'^\w+\.\w+$', label): | |
raise CommandError(u"%s doesn't look like model name" % label) | |
model = get_model(*label.split('.')) | |
if not model: | |
raise CommandError(u"Can't find model %s" % label) | |
self.handle_model(model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment