Fixed #12999 -- Modified the contenttypes syncdb handler to use db router logic. Thanks to lsbardel for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12750 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e5d23d8c47
commit
1db672f347
|
@ -7,22 +7,21 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
||||||
Creates content types for models in the given app, removing any model
|
Creates content types for models in the given app, removing any model
|
||||||
entries that no longer have a matching model class.
|
entries that no longer have a matching model class.
|
||||||
"""
|
"""
|
||||||
db = kwargs['db']
|
|
||||||
ContentType.objects.clear_cache()
|
ContentType.objects.clear_cache()
|
||||||
content_types = list(ContentType.objects.using(db).filter(app_label=app.__name__.split('.')[-2]))
|
content_types = list(ContentType.objects.filter(app_label=app.__name__.split('.')[-2]))
|
||||||
app_models = get_models(app)
|
app_models = get_models(app)
|
||||||
if not app_models:
|
if not app_models:
|
||||||
return
|
return
|
||||||
for klass in app_models:
|
for klass in app_models:
|
||||||
opts = klass._meta
|
opts = klass._meta
|
||||||
try:
|
try:
|
||||||
ct = ContentType.objects.using(db).get(app_label=opts.app_label,
|
ct = ContentType.objects.get(app_label=opts.app_label,
|
||||||
model=opts.object_name.lower())
|
model=opts.object_name.lower())
|
||||||
content_types.remove(ct)
|
content_types.remove(ct)
|
||||||
except ContentType.DoesNotExist:
|
except ContentType.DoesNotExist:
|
||||||
ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
|
ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
|
||||||
app_label=opts.app_label, model=opts.object_name.lower())
|
app_label=opts.app_label, model=opts.object_name.lower())
|
||||||
ct.save(using=db)
|
ct.save()
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
|
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
|
||||||
# The presence of any remaining content types means the supplied app has an
|
# The presence of any remaining content types means the supplied app has an
|
||||||
|
|
Loading…
Reference in New Issue