I need the name of the project (field project, no translation) for build the path of upload_to directory in ImageField. But i get this error:
AttributeError at /admin/api/stage/add/ 'StageTranslation' object has no attribute 'project'
def stage_name_path(instance, filename):
# get error at instance.project
return '/'.join(filter(None, (instance.project, 'stages', filename)))
class Stage(TranslatableModel):
name = models.CharField(
'Short name',
max_length=50
)
text = models.CharField(
'Text',
max_length=120
)
translations = TranslatedFields(
image=models.ImageField(
'Image (i18n)',
upload_to=stage_name_path
),
)
project = models.ForeignKey(Project, related_name='stages')
Through the instance I can access the fields with translation (image) but I can not access the fields name, text or project... the ones who really need.
Try:
instance.master.project
. TheStageTranslation
has aForeignKey
fieldmaster
is a reference toSage
.