使用django时正确生成复数
inflect_dj的Python项目详细描述
名称
implect_dj.py-生成与django一起使用的复数。
版本
本文档描述了0.2.0版的inflect_dj.py
安装
pip install inflect_dj
或
easy_install inflect_dj
说明
@复数 -
djangomodels.Model类的装饰器。
用@verbose_name_plural装饰model.Model的子类将确保 模型名称的复数形式将正确呈现。
它使用模块inflect.py来确定正确的多元化。
使用量
Using ^{tt5}$ when specifying a ^{tt8}$ for the model:
from django.db import models from inflect_dj import verbose_name_plural @verbose_name_plural class mycategory(models.Model): [definition of the model] class Meta: verbose_name = 'category' [rest of the Meta class definition]The plural will be displayed correctly as ^{tt9}$.
使用@verbose_name_plural而不指定verbose_name:
from django.db import models from inflect_dj import verbose_name_plural @verbose_name_plural class category(models.Model): [definition of the model] class Meta: [class Meta definition]The plural will be displayed correctly as ^{tt9}$, as this is the plural of the class name.
早期版本的python
如果使用的是早于2.6的python版本,则不能使用 类修饰符,并且必须通过调用 verbose_name_plural():
from django.db import models from inflect_dj import verbose_name_plural class mycategory(models.Model): [definition of the model] class Meta: verbose_name = 'category' [rest of the Meta class definition] mycategory = verbose_name_plural(mycategory)
版权所有
Copyright (C) 2010 Paul Dyson
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
This module can be downloaded at http://pypi.python.org/pypi/inflect_dj
This module can be installed via ^{tt2}$
Repository available at http://github.com/pwdyson/inflect_dj.py