Skip to content

Instantly share code, notes, and snippets.

@Suor
Created September 7, 2012 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suor/3663735 to your computer and use it in GitHub Desktop.
Save Suor/3663735 to your computer and use it in GitHub Desktop.
django ModelCommand
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