Guest User

Untitled

a guest
Jun 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class Category(models.Model):
  2. name = models.CharField()
  3. description = models.TextField()
  4.  
  5. class CategoryTranslation(models.Model):
  6. name = models.CharField()
  7. description = models.TextField()
  8. category = models.ForeignKey(Category, related_name="translations")
  9. language = models.ForeignKey(Language)
  10.  
  11. class Meta:
  12. unique_together = ('category', 'language')
  13.  
  14. ## "the problem" [plain_text]
  15.  
  16. I could to so I've a method on the category class like "translated_name"
  17. that take an argument language but the best solution
  18. - what I think - should be to pass some value like this:
  19.  
  20. ## Example code
  21.  
  22. LocaleSettings.language = "en"
  23. category = Category.objects.get(id=1)
  24. print category.name
  25. => "Hi You" (en / english)
  26.  
  27. LocaleSettings.language = "de"
  28. category = Category.objects.get(id=1)
  29. print category.name
  30. => "Hallo Sie" (de / Deutch/German)
Add Comment
Please, Sign In to add comment