Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin site and read only field 'language_code' in Inlines... #9

Open
tarak opened this issue Oct 30, 2012 · 0 comments
Open

Admin site and read only field 'language_code' in Inlines... #9

tarak opened this issue Oct 30, 2012 · 0 comments

Comments

@tarak
Copy link
Contributor

tarak commented Oct 30, 2012

I made an app where translated entries are added by using fixtures.
I wanted to integrate the app in the admin site, but only to see what
translations are available, so I just set readonly_fields on the admin inline
to contain the field 'language_code'. And it raised an error...

Reproducing the error:

My models.py looks like this:

from django.db import models
from django.utils.translation import ugettext_lazy as _
from multilingual_model.models import MultilingualModel
from multilingual_model.models import MultilingualTranslation


class MyModelTranslation(MultilingualTranslation):
    parent = models.ForeignKey('MyModel',
                               related_name='translations')
    name = models.CharField(max_length=200)

    class Meta:
        ordering = ['language_code']
        unique_together = ('parent', 'language_code')


class MyModel(MultilingualModel):
    code = models.CharField(db_index=True, max_length=16)

    class Meta:
        ordering = ['code']

    def __unicode__(self):
        u = self.unicode_wrapper('name', default=_('Unnamed'))

My admin.py looks like this:

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from multilingual_model.admin import TranslationTabularInline

from myapp.models import MyModel, MyModelTranslation


class MyModelTranslationInline(TranslationTabularInline):
    extra=0
    can_delete = False
    model = MyModelTranslation
    readonly_fields = ('name', 'language_code')


class MyModelAdmin(admin.ModelAdmin):
    inlines = [MyModelTranslationInline]

admin.site.register(MyModel, MyModelAdmin)

This raises a KeyError because the field 'language_code' is not available in the
form:

Django Version: 1.5.dev20121025064951
Exception Type: KeyError
Exception Value: 'language_code'
Exception Location: /usr/local/lib/python2.7/dist-packages/multilingual_model/forms.py in _construct_available_languages, line 56
Python Executable: /usr/bin/python
Python Version: 2.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant