misc: workaround migration order, lazy load cells if contenttypes is not ready

This commit is contained in:
Frédéric Péters 2015-11-23 18:44:59 +01:00
parent 140d5d5393
commit 382ee37f12
1 changed files with 12 additions and 1 deletions

View File

@ -31,11 +31,22 @@ class Library(object):
# initialize the dictionary
self.classes_by_content_str = {}
for klass in self.classes:
content_type = ContentType.objects.get_for_model(klass)
try:
content_type = ContentType.objects.get_for_model(klass)
except RuntimeError:
# this is for RuntimeError: Error creating new content types.
# Please make sure contenttypes is migrated before trying to
# migrate apps individually.
#
# If that happens we switch to lazy initialization.
self.classes_by_content_str = None
break
content_type_str_v = '%s_%s' % (content_type.app_label, content_type.model)
self.classes_by_content_str[content_type_str_v] = klass
def get_cell_class(self, content_type_str):
if self.classes_by_content_str is None:
self.ready()
return self.classes_by_content_str[content_type_str]
def register_cell_class(self, klass):