Giter Site home page Giter Site logo

django-diplomat's Introduction

Diplomat

Diplomat provides Django models for the countries and languages covered by the ISO 3166 and ISO 639 standards, respectively. Diplomat is implemented as a wrapper around a subset of pycountry, and its interface should feel familiar to users of that module.

Installation

Add diplomat to your INSTALLED_APPS, then run the syncdb command, which will create the required language and country models.

Model Usage

Diplomat's field models exactly mirror the attributes of the pycountry database objects that they imitate. In addition to these attributes, custom manager methods are available for some of the objects provided by diplomat.

Languages

The ISOLanguage model is a wrapper around the pycountry.db.Language model.

>>> from diplomat.models import ISOLanguage
>>> aragonese = ISOLanguage.objects.get(alpha2='an')
>>> aragonese.alpha2
u'an'
>>> aragonese.bibliographic
u'arg'
>>> aragonese.terminology
u'arg'
>>> aragonese.name
u'Aragonese'

In addition, it provides a custom model manager.

>>> from diplomat.models import ISOLanguage
>>> all_languages = ISOLanguage.objects.all()
>>> basic_languages = ISOLanguage.objects.basic()
>>> usable_languages = ISOLanguage.objects.usable()
>>> all_languages.count() > usable_languages.count() > basic_languages.count()
True
>>> all([l.alpha2 for l in all_languages])
False
>>> all([l.alpha2 for l in basic_languages])
True
>>> all_languages.filter(terminology='zxx').count()
1
>>> usable_languages.filter(terminology='zxx').count()
0

Countries

The ISOCountry model is a wrapper around the pycountry.db.Country model.

>>> from diplomat.models import ISOCountry
>>> germany = ISOCountry.objects.get(alpha2='DE')
>>> germany.alpha2
u'DE'
>>> germany.alpha3
u'DEU'
>>> germany.numeric
u'276'
>>> germany.name
u'Germany'
>>> germany.official_name
u'Federal Republic of Germany'

Field Usage

Diplomat provides a series of simple form fields for selecting country and language objects. These fields, which can be imported from diplomat.fields, are as follows:

LanguageChoiceField
A field for selecting a single usable language.

LanguageMultipleChoiceField
A field for selecting multiple usable languages.

BasicLanguageChoiceField
A field for selecting a single basic language covered by ISO 639-1.

BasicLanguageMultipleChoiceField
A field for selecting multiple basic languages covered by ISO 639-1.

CountryChoiceField
A field for selecting a single country.

CountryMultipleChoiceField
A field for selecting multiple countries.

django-diplomat's People

Contributors

cilcoberlin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.