如何verbose_name
在每个字段上不使用参数的情况下翻译 django 模型?发生通过寻找添加新字段并verbose_name
通过字段名称自动为其提供参数的中间类继承所有模型的练习?还是将翻译整合到表格中的最佳实践?也许我应该verbose_name
在创建时提供每个模型属性?
我不想这样做:
class Currency(models.Model):
name=models.CharField(max_length=32, verbose_name=_("name"))
symbol=models.CharField(max_length=32, verbose_name=_("symbol"))
iso_4217=models.CharField(max_length=3)
def __unicode__(self):
return self.name
class Meta:
verbose_name=_(u'currency')
verbose_name_plural=_(u'currencies')
我想做这样的事情:
class BaseModel(models.Model):
__setattr__(self, name, value):
''' Some needles parts of method was cutted out to make it easily
'''
value.verbose_name=_(name)
value.verbose_name_plural=_("%ss" % name)
self.super(BaseModel, name, value)
class Currency(models.Model):
''' Every field of this class whould be supplied by verbose_name and verbose_name_plural
'''
name=models.CharField(max_length=32)
symbol=models.CharField(max_length=32)
iso_4217=models.CharField(max_length=3)
也许 django 有自己的解决方案?