On Thu, 11 Jan 2007 16:58:34 -0600, Jacob Kaplan-Moss wrote:
On 1/11/07 2:35 PM, Nuno Mariz wrote:
Any idea to resolve this , this don't scale. If I what to add another
language, I have to patch all of my templates.
If I were you, I'd write a simple accessor on your model to get the current
translation. Off the top of my head, you could do something like::
from django.utils import translation
class MyModel(Model):
text_pt = TextField()
text_en = TextField()
def get_text(self):
text_field = "text_%s" % translation.get_language()
return getattr(self, text_field)
Then in a template you can just do::
{{ myobject.get_text }}
Jacob
This solution seems simple, but there's a problem when you put something
like this in your model:
class MyModel(models.Model):
text_en = TextField()
text_pt-br = TextField()
Django complains with a SyntaxError: can't assign to operator on
"text_pt-br = TextField()" line
This just what I did in my models, but perhaps there's a clean way to go
about doing it right.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---