adding an amo compatiblity model and translation helpers

This commit is contained in:
Jeff Balogh 2009-10-21 17:33:00 -07:00
Родитель 4af097c67e
Коммит 74808c425d
3 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,5 @@
"""
Miscellaneous helpers that make Django compatible with AMO.
"""
from .models import LegacyModel, TranslatedField

32
apps/amo/models.py Normal file
Просмотреть файл

@ -0,0 +1,32 @@
from django.db import models
class LegacyModel(models.Model):
"""Adds automatic created and modified fields to the model."""
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class TranslatedField(models.IntegerField):
__metaclass__ = models.SubfieldBase
def to_python(self, value):
locale = 'en-US'
q = Translation.objects.filter(id=value, locale=locale)
v = q.values_list('localized_string', flat=True)
return v[0] if v else value
# Putting Translation in here since TranslatedField depends on it.
class Translation(LegacyModel):
autoid = models.AutoField(primary_key=True)
id = models.IntegerField()
locale = models.CharField(max_length=10)
localized_string = models.TextField()
class Meta:
db_table = 'translations'

Просмотреть файл

@ -84,6 +84,8 @@ TEMPLATE_DIRS = (
)
INSTALLED_APPS = (
'amo',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',