def __init__(self, name, app_label):
# by changing app_label here to 'wagtailcore' we trick Django migrations system
# to think that this migration belongs to wagtailcore app
# this is necessary to make model name resolution work
app_label = 'wagtailcore'
super(Migration, self).__init__(name, app_label)
# find last wagtailcore migration
mod_name = MigrationLoader.migrations_module(app_label)
if DJANGO_VERSION >= (1, 11):
# Django 1.11 returns tuple(str, bool) while older versions return str
mod_name = mod_name[0]
mod = import_module(mod_name)
migrations = []
# this loop acts the same way as MigrationLoader.
for name in os.listdir(os.path.dirname(mod.__file__)):
if not name.endswith('.py'):
continue
import_name = name.rsplit('.', 1)[0]
if import_name[0] in '_.~':
continue
migrations.append(import_name)
last_migration = sorted(migrations, reverse=True)[0]
# By using `replaces` we make sure that this migration doesn't have ambiguous `app_label`.
# When this migration is applied Django writes only replaced migration
# to django_migrations table in DB. Otherwise migration would have
# 'wagtailtranslation' as app_label in django_migrations table and
# `migrate` command would consider this migration as unapplied due
# to app_label mismatch.
self.replaces = [
(app_label, last_migration),
]
# import operations from wagtail migration we are replacing
# and prepend them to operations of this migration
mod_path = '{}.{}'.format(mod_name, last_migration)
orig_migration = import_module(mod_path).Migration
self.operations[:0] = orig_migration.operations
self.dependencies = orig_migration.dependencies
# Dynamically define AddField operations for all Page field translations.
# This always uses current AVAILABLE_LANGUAGES setting.
# In case languages are changed after running this migration, `makemigrations`
# command would do nothing for Page model. One would have to run `sync_translation_fields`
# command from modeltranslation to get DB schema in sync.
9999_wagtail_translation.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录