mirror of
https://github.com/Hopiu/wagtail-modeltranslation.git
synced 2026-03-16 22:10:30 +00:00
commit
a323535582
9 changed files with 113 additions and 2 deletions
|
|
@ -57,13 +57,30 @@ The ``makemigrations_translation`` Command
|
|||
``wagtail-modeltranslation`` patches Wagtail's ``Page`` model and as consequence Django's original
|
||||
``makemigrations`` commmand will create migrations for ``Page`` which may create conflicts with
|
||||
other migrations. To circumvent this issue ``makemigrations_translation`` hides any ``Page`` model changes
|
||||
and creates all other migrations as usual. Use this command as an alterntive to Django's own
|
||||
and creates all other migrations as usual. Use this command as an alternative to Django's own
|
||||
``makemigrations`` or consider using :ref:`management_commands-makemigrations`.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python manage.py makemigrations_translation
|
||||
|
||||
.. _management_commands-migrate_translation:
|
||||
|
||||
The ``migrate_translation`` Command
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. versionadded:: 0.8
|
||||
|
||||
Since :ref:`management_commands-makemigrations_translation` hides any ``Page`` model changes, Django's own
|
||||
``migrate`` command won't be able to update ``wagtailcore_page`` table with new translation fields. In order to
|
||||
correctly update the database schema a combination of ``migrate`` followed by :ref:`sync_page_translation_fields`
|
||||
is usually required. ``migrate_translation`` provides a shortcut to running these two commands. Use this
|
||||
as an alternative to Django's own ``migrate`` or consider using :ref:`management_commands-migrate`.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python manage.py migrate_translation
|
||||
|
||||
.. _management_commands-set_translation_url_paths:
|
||||
|
||||
The ``set_translation_url_paths`` Command
|
||||
|
|
@ -109,3 +126,41 @@ this will likely create invalid ``Page`` migrations, do this only if you know wh
|
|||
.. code-block:: console
|
||||
|
||||
$ python manage.py makemigrations_original
|
||||
|
||||
|
||||
.. _management_commands-wagtail_modeltranslation.migrate:
|
||||
|
||||
wagtail_modeltranslation.migrate
|
||||
---------------------------------
|
||||
|
||||
To use ``wagtail_modeltranslation.migrate`` module commands add ``'wagtail_modeltranslation.migrate,'``
|
||||
to ``INSTALLED_APPS``. This module adds the following management commands.
|
||||
|
||||
.. _management_commands-migrate:
|
||||
|
||||
The ``migrate`` Command
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This command is a proxy for :ref:`management_commands-migrate_translation`. It has the added benefit of
|
||||
overriding Django's own ``migrate`` saving the need to additionally run :ref:`sync_page_translation_fields`.
|
||||
See `issue #175
|
||||
<https://github.com/infoportugal/wagtail-modeltranslation/issues/175#issuecomment-368046055>`_ to understand
|
||||
how this command can be used to create translation fields in a test database.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python manage.py migrate
|
||||
|
||||
.. _management_commands-migrate_original:
|
||||
|
||||
The ``migrate_original`` Command
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Since Django's ``migrate`` is overriden by ``wagtail-modeltranslation``'s version use
|
||||
``migrate_original`` to run the Django's original ``migrate`` command. Please note
|
||||
this will not update ``wagtailcore_page`` table with new translation fields, use
|
||||
:ref:`sync_page_translation_fields` for that.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python manage.py migrate_original
|
||||
|
|
|
|||
5
setup.py
5
setup.py
|
|
@ -24,7 +24,10 @@ setup(
|
|||
'wagtail_modeltranslation.templatetags',
|
||||
'wagtail_modeltranslation.makemigrations',
|
||||
'wagtail_modeltranslation.makemigrations.management',
|
||||
'wagtail_modeltranslation.makemigrations.management.commands'],
|
||||
'wagtail_modeltranslation.makemigrations.management.commands',
|
||||
'wagtail_modeltranslation.migrate',
|
||||
'wagtail_modeltranslation.migrate.management',
|
||||
'wagtail_modeltranslation.migrate.management.commands'],
|
||||
package_data={'wagtail_modeltranslation': ['static/wagtail_modeltranslation/css/*.css',
|
||||
'static/wagtail_modeltranslation/js/*.js']},
|
||||
install_requires=[
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
from django.core.management.commands.migrate import Command as MigrateCommand
|
||||
from django.db.migrations.autodetector import MigrationAutodetector
|
||||
from .sync_page_translation_fields import Command as SyncPageTranslationFieldsCommand
|
||||
|
||||
|
||||
# decorate MigrationAutodetector.changes so we can silence any wagtailcore migrations missing warnings
|
||||
def changes_decorator(func):
|
||||
def wrapper(self, graph, trim_to_apps=None, convert_apps=None, migration_name=None):
|
||||
changes = func(self, graph, trim_to_apps, convert_apps, migration_name)
|
||||
if 'wagtailcore' in changes:
|
||||
del changes['wagtailcore']
|
||||
return changes
|
||||
return wrapper
|
||||
|
||||
|
||||
class Command(MigrateCommand):
|
||||
help = "Updates database schema. Manages both apps with migrations and those without. " \
|
||||
"Updates Wagtail Page translation fields"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
old_autodetector_changes = MigrationAutodetector.changes
|
||||
MigrationAutodetector.changes = changes_decorator(MigrationAutodetector.changes)
|
||||
|
||||
try:
|
||||
super(Command, self).handle(*args, **options)
|
||||
finally:
|
||||
MigrationAutodetector.changes = old_autodetector_changes
|
||||
|
||||
# Run sync_page_translation_fields command
|
||||
sync_page_command = SyncPageTranslationFieldsCommand()
|
||||
# Update the dict of sync_page_command with the content of this one
|
||||
sync_page_command.__dict__.update(self.__dict__)
|
||||
sync_page_command.handle(*args, **options)
|
||||
3
wagtail_modeltranslation/migrate/__init__.py
Normal file
3
wagtail_modeltranslation/migrate/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# coding: utf-8
|
||||
|
||||
default_app_config = 'wagtail_modeltranslation.migrate.apps.MigrateConfig'
|
||||
7
wagtail_modeltranslation/migrate/apps.py
Normal file
7
wagtail_modeltranslation/migrate/apps.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MigrateConfig(AppConfig):
|
||||
name = 'wagtail_modeltranslation.migrate'
|
||||
label = 'wagtail_modeltranslation_migrate'
|
||||
verbose_name = "Wagtail Modeltranslation migrate"
|
||||
0
wagtail_modeltranslation/migrate/management/__init__.py
Normal file
0
wagtail_modeltranslation/migrate/management/__init__.py
Normal file
0
wagtail_modeltranslation/migrate/management/commands/__init__.py
Executable file
0
wagtail_modeltranslation/migrate/management/commands/__init__.py
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
from wagtail_modeltranslation.management.commands.migrate_translation import Command as MigrateCommand
|
||||
|
||||
|
||||
class Command(MigrateCommand):
|
||||
pass
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
from django.core.management.commands.migrate import Command as MigrateCommand
|
||||
|
||||
|
||||
class Command(MigrateCommand):
|
||||
pass
|
||||
Loading…
Reference in a new issue