使用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来确定正确的多元化。

使用量

  1. 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}$.
  1. 使用@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)

作者

保罗·戴森(pwdyson@yahoo.com

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JPA。Eclipselink没有为mySQL提供密码,但它应该提供   我的Servlet和@FormDataParam存在java问题   java将什么作为上下文参数传递到文件I/O方法中?   如果两个值相同,java无法找到其中一个单选按钮   java在变量和方法名中使用下划线   JavaSpringMVC单线程安全?   klazz类的java Arraylist(反射Api)   java如何在数字字符串中查找最频繁的数字?   JavaAPI设计:使数据更易于阅读与强制更多API调用   JavaHadoopMapReduceforGoogleWebGraph   java无法启动gauge API:Runner意外退出   java如何在bluemix上使用ibm工作负载调度器?   拉取一年中某一周特定日期的所有日期   java为什么是我的角节点。js应用程序将图像上传到S3� 邮递员正确上传时的符号?   在不使用任何第三方jar的情况下将文件从本地传输到linux系统(java代码)   java将现有文件夹复制到Eclipse工作区中新创建的项目中   Java中的regex RegExp帮助   当使用“系统”外观时,Java组合框setSelectedItem会出现故障   JavaASM:在类的方法中获取局部变量名和值