Package: emencia.django.countries
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.ContentsLinksRequiresInstallUsageTemplate Context ProcessorsTemplate tagsChangelogVersion 0.2.1 - 2015/12/10Version 0.2.0 - 2015/12/10Version 0.1.1 - 2013/09/26Version 0.1 - 2013/05/03LinksDownload hisPyPi package;Clone it on hisrepository;Requiressetuptools;Django>= 1.4 (should be compatible toDjango 1.8and beyond);InstallFirst install the package:pip install emencia.django.countriesAdd it to your installed Django apps in settings:INSTALLED_APPS=(...'emencia.django.countries',...)Finally run the Django commandsmigrateto install app database tables, this will also fillCountrymodel with initial datas for countries.UsageBy default when the fixture is loaded all the countries a leveled to 0,
the default and displayed by alphabetical order.>>>fromemencia.django.countries.modelsimportCountry>>>Country.objects.all()[<Country:Afghanistan>,<Country:Albania>,<Country:Algeria>,'...(remaining elements truncated)...']So if you don’t want to displayAfghanistanas the first country of your list,
you have a set a high value to thelevelattribute 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 ProcessorsSometimes 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_LISTCOUNTRIES_LIST_LEVELEDTemplate tagsBut in general it’s a waste of ressources to have all the countries loaded in the context,
because it make a database request for each request, so template tags have been implemented.In your templates, to get the countries list, simply do this.{% load countries_tags %}

{% get_countries %}It will load the countries list in the local context of the template, in a variable namedCOUNTRIESBut if you want to change the name of this variable use this syntax.{% get_countries as MY_COUNTRIES %}If you only want to have the short list of countries, use this tag.{% get_countries_leveled as MY_COUNTRIES %}Of course the same syntax apply to this tag.ChangelogVersion 0.2.1 - 2015/12/10Fixed bad path forHISTORY.rstinsetup.py;Version 0.2.0 - 2015/12/10Ensure compatibility withDjango>=1.7:Added compatibility support in model manager withget_querysetmethod;Added Django migration;Now loading initial data fixtures from a data migration sinceDjango>=1.7don’t do it automatically anymore;Update setup.py for better package classifier and packages infos;Version 0.1.1 - 2013/09/26Fix package MANIFEST for missing rule for fixture data file;Version 0.1 - 2013/05/03First release as a package;