Skip to main content

Correctly generate plurals when using Django

Project description

NAME

inflect_dj.py - Generate plurals for use with Django.

VERSION

This document describes version 0.1.2 of inflect_dj.py

INSTALLATION

pip install inflect_dj

or

easy_install inflect_dj

DESCRIPTION

@pl

Decorator for the Django models.Model classes.

Decorating a child class of model.Model with @pl will ensure that the plural form of the model name will be rendered correctly.

@pl will set Meta.verbose_name_plural to the correct plural of the model name or the correct plural of Meta.verbose_name if it is provided.

It uses the module inflect.py to determine the correct pluralisation.

USAGE

  1. Using @pl when specifying a verbose_name for the model:

    from django.db import models
    from inflect_dj import pl
    
    @pl
    class mycategory(models.Model):
        [definition of the model]
        class Meta:
            verbose_name = 'category'
            [rest of the Meta class definition]

The @pl decorator will set Meta.verbose_name_plural to 'categories', ensuring the plural will be displayed correctly.

  1. Using @pl without specifying verbose_name:

    from django.db import models
    from inflect_dj import pl
    
    @pl
    class category(models.Model):
        [definition of the model]
        class Meta:
            [class Meta definition]

    The @pl decorator will set Meta.verbose_name_plural to 'categories', as this is the plural of the class name.

Earlier versions of Python

If you are using a Python version earlier than 2.6 you cannot use class decorators and must explicitly redefine the class with a call to pl():

from django.db import models
from inflect_dj import pl

class mycategory(models.Model):
    [definition of the model]
    class Meta:
        verbose_name = 'category'
        [rest of the Meta class definition]
mycategory = pl(mycategory)

AUTHOR

Paul Dyson (pwdyson@yahoo.com)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inflect_dj-v0.1.2.tar.gz (14.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page