I'm going to prepare multilanguage cms django app and I need to enable in 
django admin adding and editing entries with content in many languages.
My idea is to have a separated record for content in each language and 
relate it to the entry like in the example:

*setting.py*
LANGUAGES = (
    ('en', 'English'),
    ('pl', 'Polski'),
)

*app/models.py*
class Entry(models.Model):
    pub_date = models.DateField(auto_now_add=True)
    featured = models.BooleanField()

class Base_Content(models.Model):
    lang = models.CharField(max_length=5, choices=settings.LANGUAGES)
    entry = models.ForeignKey('Entry',
        related_name="%(app_label)s_%(class)s_related")
    content = models.TextField()

    class Meta:
        abstract = True

class Title_Content(Base_Content):
    pass

class Body_Content(Base_Content):
    pass
*
app/admin.py*
class TitleInline(admin.TabularInline):
    formfield_overrides = {models.TextField: {'widget': TextInput}, }
    model = Title_Content
    max_num = len(settings.LANGUAGES)
    readonly_fields = ['lang', ]

class BodyInline(admin.TabularInline):
    model = Body_Content
    max_num = len(settings.LANGUAGES)
    readonly_fields = ['lang', ]

class EntryAdmin(admin.ModelAdmin):
    inlines = [TitleInline, BodyInline]

admin.site.register(Entry, EntryAdmin)

I need to display in inline only as many related content forms as there are 
languages set in LANGUAGES and each form is supposed to be displayed with 
already set language field, that is, when there are two languages, like in 
the example, there need to be two title forms, one with 'lang' field set 
already to 'en' and the second one set to 'pl' - no matter there is or not 
a record for the content in the db yet.

I can't figure out how to modify data that is going to be displayed in 
inlines. Or maybe there is other solution available

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to