Reputation: 21
I'm trying to do this works
admin.py
class TapasInline(TranslatableStackedInline):
model = Tapa
can_delete = True
extra = 0
verbose_name = 'Tapas'
verbose_name_plural = 'Tapas'
fields = ('name','description','photo', 'tags')
...
class BarAdmin(TranslatableAdmin):
inlines = (TapasInline,)
...
admin.site.register(Bar,BarAdmin)
models.py
class Tapa(TranslatableModel):
translations = TranslatedFields(
name = models.CharField(max_length=255,verbose_name='Nombre de la tapa'),
description = models.TextField(verbose_name='Descripcion de la tapa')
)
photo = models.ImageField(verbose_name='Foto de la tapa')
average_rating = models.FloatField(verbose_name='Puntuación media de la tapa',default=-1)
bar = models.ForeignKey(Bar,verbose_name='Bar')
tags = models.ManyToManyField(Tag,verbose_name='Etiquetas')
def __unicode__(self):
return self.lazy_translation_getter('name')
,but I'm getting this error :
hvad.exceptions.WrongManager: To access translated fields like 'name' from an untranslated model, you must use a translation aware manager. For non-translatable models, you can get one using hvad.utils.get_translation_aware_manager.
For translatable models, use the language() method.
[Django==1.8]
What am I doing wrong? How can I solve it?
Thanks in advance
Upvotes: 2
Views: 926
Reputation: 13552
Unfortunately, the direct use of translated fields in admin options is not supported yet. It will be in next release (for most of them).
The culprit code is in the admin's system checks module. It would work, but the system check included in admin really insists that it will not allow a field it does not recognize.
In the meantime, you can work around the admin check by using a get_fields
method instead of a fields
attribute. This should do the trick:
def get_fields(self, request, obj=None):
return ('name','description','photo', 'tags')
Please tell me if it works. I'd have answered sooner, but I don't hang around here much.
Upvotes: 2