I tried the first 2 items from Django Packages. And I found that django-hvad is better for me.
Last active
December 20, 2015 01:49
-
-
Save hktonylee/6051896 to your computer and use it in GitHub Desktop.
django-hvad Sample Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
import models | |
from models import Portal | |
from hvad.admin import TranslatableAdmin, InlineModelForm | |
class PortalAdmin(TranslatableAdmin): | |
# Don't use this: | |
# fields = ('title', 'description', ) | |
# !!! Here is the magic !!! | |
def get_fieldsets(self, request, obj=None): | |
return ( | |
("General", { | |
"fields": ( | |
"title", | |
), | |
}), | |
("Localizables", { | |
"fields": ( | |
"description", | |
"details", | |
) | |
}) | |
) | |
admin.site.register(models.Portal, PortalAdmin) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from hvad.models import TranslatableModel, TranslatedFields | |
class Portal(TranslatableModel): | |
title = models.CharField(max_length = 100, blank=True) | |
translations = TranslatedFields( | |
description = models.TextField(blank=True), | |
details = models.CharField(max_length=255), | |
) | |
def __unicode__(self): | |
return self.title | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment