def modeltranslation_fields(self): """ Helper function for generating modeltranslation multi language fields. Args: self: (south.v2.SchemaMigration): Migrations instance. Returns: tuple: tuple with modeltranslation fields. """ if modeltranslation(): title = tuple([("title_{language}".format(**{ "language": language, }), self.gf("django.db.models.fields.CharField")(db_index=True, max_length=255, null=True, blank=True)) for language in list(dict(settings.LANGUAGES).keys())]) text = tuple([("text_{language}".format(**{ "language": language, }), self.gf("django.db.models.fields.TextField")(null=True, blank=True)) for language in list(dict(settings.LANGUAGES).keys())]) return title + text else: return tuple()
class Meta: if modeltranslation(): widgets = dict([("text_{language}".format(**{"language": language.replace("-", "_"), }), RedactorEditor()) for language in list(dict(settings.LANGUAGES).keys())]) else: widgets = { "text": RedactorEditor() }
class PageHelpAdmin(TabbedDjangoJqueryTranslationAdmin if modeltranslation() else admin.ModelAdmin): """ Customize PageHelp model for admin area. """ list_display = [ "page", "title", ] search_fields = [ "title", ] list_filter = [ "page", ] form = PageHelpAdminForm
from django.conf import settings from simple_help.utils import modeltranslation MODELTRANSLATION_FIELDS = [ ("title_{language}".format(**{ "language": language, }), models.CharField( max_length=255, null=True, verbose_name="help title", db_index=True)) for language in list(dict(settings.LANGUAGES).keys()) ] + [("text_{language}".format(**{ "language": language, }), models.TextField(null=True, verbose_name="help text")) for language in list(dict(settings.LANGUAGES).keys()) ] if modeltranslation() else [] class Migration(migrations.Migration): dependencies = [] operations = [ migrations.CreateModel( name="PageHelp", fields=[ ("id", models.AutoField(verbose_name="ID", serialize=False, auto_created=True, primary_key=True)), ("page",
"PageHelpAdmin", ] class PageHelpAdmin(TabbedDjangoJqueryTranslationAdmin if modeltranslation() else admin.ModelAdmin): """ Customize PageHelp model for admin area. """ list_display = [ "page", "title", ] search_fields = [ "title", ] list_filter = [ "page", ] form = PageHelpAdminForm if modeltranslation(): # registering translation options translator.register(PageHelp, PageHelpTranslationOptions) # registering admin custom classes admin.site.register(PageHelp, PageHelpAdmin)
class Migration(SchemaMigration): def forwards(self, orm): # Adding model "PageHelp" db.create_table("simple_help_pagehelp", ( ("id", self.gf("django.db.models.fields.AutoField")(primary_key=True)), ("page", self.gf("django.db.models.fields.IntegerField")( default=0, unique=True, db_index=True)), ("title", self.gf("django.db.models.fields.CharField")( max_length=255, db_index=True)), ("text", self.gf("django.db.models.fields.TextField")()), ) + modeltranslation_fields(self)) db.send_create_signal("simple_help", ["PageHelp"]) def backwards(self, orm): # Deleting model "PageHelp" db.delete_table(u"simple_help_pagehelp") models = { "simple_help.pagehelp": { "Meta": { "object_name": "PageHelp" }, "id": ("django.db.models.fields.AutoField", [], { "primary_key": "True" }), "page": ("django.db.models.fields.IntegerField", [], { "default": "0", "unique": "True", "db_index": "True" }), "text": ("django.db.models.fields.TextField", [], {}), "title": ("django.db.models.fields.CharField", [], { "max_length": "255", "db_index": "True" }), } } if modeltranslation(): for language in list(dict(settings.LANGUAGES).keys()): # add modeltranslation fields models["simple_help.pagehelp"].update({ "title_{language}".format(**{ "language": language, }): ("django.db.models.fields.TextField", [], { "null": "True", "blank": "True" }) }) models["simple_help.pagehelp"].update({ "text_{language}".format(**{ "language": language, }): ("django.db.models.fields.TextField", [], { "null": "True", "blank": "True" }) }) complete_apps = ["simple_help"]