Skip to content

Instantly share code, notes, and snippets.

@hktonylee
Last active December 20, 2015 01:49
Show Gist options
  • Save hktonylee/6051896 to your computer and use it in GitHub Desktop.
Save hktonylee/6051896 to your computer and use it in GitHub Desktop.
django-hvad Sample Code
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)

I tried the first 2 items from Django Packages. And I found that django-hvad is better for me.

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