List of manageable countries for your Django projects
Project description
A Django application who contains world country list that can be displayed with a priority order.
Usefull for forms or for models which needs a country list ordered.
Links
Download his PyPi package;
Clone it on his repository;
Requires
setuptools;
Django >= 1.4 (should be compatible to Django 1.8 and beyond);
Install
First install the package:
pip install emencia.django.countries
Add it to your installed Django apps in settings:
INSTALLED_APPS = (
...
'emencia.django.countries',
...
)
Finally run the Django commands migrate to install app database tables, this will also fill Country model with initial datas for countries.
Usage
By default when the fixture is loaded all the countries a leveled to 0, the default and displayed by alphabetical order.
>>> from emencia.django.countries.models import Country
>>> Country.objects.all()
[<Country: Afghanistan>, <Country: Albania>, <Country: Algeria>, '...(remaining elements truncated)...']
So if you don’t want to display Afghanistan as the first country of your list, you have a set a high value to the level attribute for all the countries you want.
Now if you want to retrieve your country list ordered do this:
>>> france = Country.objects.get(iso='FR')
>>> france.level = 100
>>> france.save()
>>> Country.objects.all()
[<Country: France>, <Country: Afghanistan>, <Country: Albania>, '...(remaining elements truncated)...']
But if you only want a short list of countries with the level attribute set, you can do this:
>>> Country.objects.leveled()
[<Country: France>]
This will return only the countries with a level value different than 0.
Template Context Processors
Sometimes it can be usefull to have all the countries in the context for rendering templates, so a template context processor is provided.
>>> TEMPLATE_CONTEXT_PROCESSORS = (
... # Your template context processors
... 'emencia.django.countries.context_processors.countries',
... )
This template context processor, provides 2 variables in the context :
COUNTRIES_LIST
COUNTRIES_LIST_LEVELED
Version 0.2.1 - 2015/12/10
Fixed bad path for HISTORY.rst in setup.py;
Version 0.2.0 - 2015/12/10
Ensure compatibility with Django>=1.7:
Added compatibility support in model manager with get_queryset method;
Added Django migration;
Now loading initial data fixtures from a data migration since Django>=1.7 don’t do it automatically anymore;
Update setup.py for better package classifier and packages infos;
Version 0.1.1 - 2013/09/26
Fix package MANIFEST for missing rule for fixture data file;
Version 0.1 - 2013/05/03
First release as a package;
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
File details
Details for the file emencia.django.countries-0.2.2.tar.gz
.
File metadata
- Download URL: emencia.django.countries-0.2.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8854f22172c36383ec44e2d68a07146e9869585a9badb0e28011cac6969a1f06 |
|
MD5 | 938dcf7738a23503beec589f47e3d1d8 |
|
BLAKE2b-256 | e730272880f3572bc9cd9c0ebb830a64f6f3cae7700ec747657612cc070e5acb |