0

Is it possible to translate DB entries? I have a dependent dropdown story that i need to translate. But i cant translate the dropdown fields, the fields come from other models and har hard coded. I can use HTML with JQ to achive this but i want to skip the manual labor to update the forms everytime new profession or professioncategories are added.

class Profession(models.Model):
    name = models.CharField(max_length=30),

    def __str__(self):
        return self.name

class Professioncategory(models.Model):
    profession = models.ForeignKey(Profession, on_delete=models.CASCADE)
    name = models.CharField(max_length=30)

    def __str__(self):
        return self.name

class Skills(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    active = models.BooleanField(_('Active'), default=True)
    profession = models.ForeignKey(Profession, on_delete=models.SET_NULL, null=True)
    professioncategory = models.ForeignKey(Professioncategory, on_delete=models.SET_NULL, null=True)
    posted_on = models.DateTimeField(_('Registrerad'), auto_now_add=True)
    updated_on = models.DateTimeField(_('last updated'), auto_now=True)
    years_of_exp = models.CharField(_('years of experiance'), max_length=20, choices=YEARS_OF_EXP, null=True, blank=True)
The
  • 73
  • 7
  • Do you mean translation to other languages? – Ivan Starostin Mar 24 '21 at 08:43
  • I have already implemented the translation by using i18n and everythin is working. But how do i translate database entries. I can translate using {% trans ""%} but how do i translate the inputs from a model like {{ profession.name }} i use this value in a dropdown field in a form – The Mar 24 '21 at 08:53
  • 1
    There are some packages helping to achieve this. They produce additional columns or tables for translations. – Ivan Starostin Mar 24 '21 at 08:59
  • Do you have tips, whats the name of these packages? thx – The Mar 24 '21 at 09:04
  • 1
    Such questions (recommend me a lib/book/site) a considered offtopic on SO. Please use search. There is `django-translations` for example. – Ivan Starostin Mar 24 '21 at 09:09

0 Answers0