mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 03:32:55 +03:00
This will be a superior version of LocalizedAutoSlugField, but one that doesn't have concurrency issues and takes advantage of the new UNIQUE CONSTRAINTs.
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from django.contrib.postgres.operations import HStoreExtension
|
|
from django.db import connection, migrations
|
|
from django.db.migrations.executor import MigrationExecutor
|
|
import sys
|
|
|
|
from localized_fields import (LocalizedAutoSlugField, LocalizedField,
|
|
LocalizedModel, LocalizedMagicSlugField)
|
|
|
|
|
|
def get_fake_model(name='TestModel', fields={}):
|
|
"""Creates a fake model to use during unit tests."""
|
|
|
|
attributes = {
|
|
'app_label': 'localized_fields',
|
|
'__module__': __name__,
|
|
'__name__': name
|
|
}
|
|
|
|
attributes.update(fields)
|
|
TestModel = type(name, (LocalizedModel,), attributes)
|
|
|
|
class TestProject:
|
|
|
|
def clone(self, *args, **kwargs):
|
|
return self
|
|
|
|
class TestMigration(migrations.Migration):
|
|
operations = [
|
|
HStoreExtension()
|
|
]
|
|
|
|
with connection.schema_editor() as schema_editor:
|
|
migration_executor = MigrationExecutor(schema_editor.connection)
|
|
migration_executor.apply_migration(
|
|
TestProject(),
|
|
TestMigration('eh', 'localized_fields')
|
|
)
|
|
|
|
schema_editor.create_model(TestModel)
|
|
|
|
return TestModel
|