django-countryfield


Namedjango-countryfield JSON
Version 7.6 PyPI version JSON
download
home_pagehttps://github.com/SmileyChris/django-countries/
SummaryProvides a country field for Django models.
upload_time2024-02-12 11:38:42
maintainer
docs_urlNone
authorChris Beaven
requires_python
licenseMIT
keywords django countries flags
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ================
Django Countries
================

.. image:: https://badge.fury.io/py/django-countries.svg
    :alt: PyPI version
    :target: https://badge.fury.io/py/django-countries

.. image:: https://github.com/SmileyChris/django-countries/actions/workflows/tests.yml/badge.svg
    :alt: Build status
    :target: https://github.com/SmileyChris/django-countries/actions/workflows/tests.yml

A Django application that provides country choices for use with forms, flag
icons static files, and a country field for models.

Country names are translated using Django's standard ``gettext``. If you would
like to help by adding a translation, please visit
https://www.transifex.com/smileychris/django-countries/


.. contents::
    :local:
    :backlinks: none


Installation
============

1. ``pip install django-countries``

   For more accurate sorting of translated country names, install it with the
   optional pyuca_ package:

   ``pip install django-countries[pyuca]``

2. Add ``django_countries`` to ``INSTALLED_APPS``

.. _pyuca: https://pypi.python.org/pypi/pyuca/


CountryField
============

A country field for Django models that provides all ISO 3166-1 countries as
choices.

``CountryField`` is based on Django's ``CharField``, providing choices
corresponding to the official ISO 3166-1 list of countries (with a default
``max_length`` of 2).

Consider the following model using a ``CountryField``:

.. code:: python

    from django.db import models
    from django_countries.fields import CountryField

    class Person(models.Model):
        name = models.CharField(max_length=100)
        country = CountryField()

Any ``Person`` instance will have a ``country`` attribute that you can use to
get details of the person's country:

.. code:: python

    >>> person = Person(name="Chris", country="NZ")
    >>> person.country
    Country(code='NZ')
    >>> person.country.name
    'New Zealand'
    >>> person.country.flag
    '/static/flags/nz.gif'

This object (``person.country`` in the example) is a ``Country`` instance,
which is described below.

Use ``blank_label`` to set the label for the initial blank choice shown in
forms:

.. code:: python

    country = CountryField(blank_label="(select country)")

You can filter using the full English country names in addition to country
codes, even though only the country codes are stored in the database by using
the queryset lookups ``contains``, ``startswith``, ``endswith``, ``regex``, or
their case insensitive versions. Use ``__name`` or ``__iname`` for the
``exact``/``iexact`` equivalent:

.. code:: python

    >>> Person.objects.filter(country__name="New Zealand").count()
    1
    >>> Person.objects.filter(country__icontains="zealand").count()
    1


Multi-choice
------------

This field can also allow multiple selections of countries (saved as a comma
separated string). The field will always output a list of countries in this
mode. For example:

.. code:: python

    class Incident(models.Model):
        title = models.CharField(max_length=100)
        countries = CountryField(multiple=True)

    >>> for country in Incident.objects.get(title="Pavlova dispute").countries:
    ...     print(country.name)
    Australia
    New Zealand

By default, countries are stored sorted for data consistency, and any
duplicates are removed. These behaviours can be overridden by using the field
arguments ``multiple_sort=False`` and ``multiple_unique=False`` respectively.


The ``Country`` object
----------------------

An object used to represent a country, instantiated with a two character
country code, three character code, or numeric code.

It can be compared to other objects as if it was a string containing the
country code and when evaluated as text, returns the country code.

name
  Contains the full country name.

flag
  Contains a URL to the flag. If you page could have lots of different flags
  then consider using ``flag_css`` instead to avoid excessive HTTP requests.

flag_css
  Output the css classes needed to display an HTML element as the correct flag
  from within a single sprite image that contains all flags. For example:

  .. code:: jinja

    <link rel="stylesheet" href="{% static 'flags/sprite.css' %}">
    <i class="{{ country.flag_css }}"></i>

  For multiple flag resolutions, use ``sprite-hq.css`` instead and add the
  ``flag2x``, ``flag3x``, or ``flag4x`` class. For example:

  .. code:: jinja

    <link rel="stylesheet" href="{% static 'flags/sprite-hq.css' %}">
    Normal: <i class="{{ country.flag_css }}"></i>
    Bigger: <i class="flag2x {{ country.flag_css }}"></i>

  You might also want to consider using ``aria-label`` for better
  accessibility:

  .. code:: jinja

    <i class="{{ country.flag_css }}"
        aria-label="{% blocktrans with country_code=country.code %}
            {{ country_code }} flag
        {% endblocktrans %}"></i>

unicode_flag
  A unicode glyph for the flag for this country. Currently well-supported in
  iOS and OS X. See https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
  for details.

code
  The two letter country code for this country.

alpha3
  The three letter country code for this country.

numeric
  The numeric country code for this country (as an integer).

numeric_padded
  The numeric country code as a three character 0-padded string.

ioc_code
  The three letter International Olympic Committee country code.


``CountrySelectWidget``
-----------------------

A widget is included that can show the flag image after the select box
(updated with JavaScript when the selection changes).

When you create your form, you can use this custom widget like normal:

.. code:: python

    from django_countries.widgets import CountrySelectWidget

    class PersonForm(forms.ModelForm):
        class Meta:
            model = models.Person
            fields = ("name", "country")
            widgets = {"country": CountrySelectWidget()}

Pass a ``layout`` text argument to the widget to change the positioning of the
flag and widget. The default layout is:

.. code:: python

    '{widget}<img class="country-select-flag" id="{flag_id}" style="margin: 6px 4px 0" src="{country.flag}">'


Custom forms
============

If you want to use the countries in a custom form, use the model field's custom
form field to ensure the translatable strings for the country choices are left
lazy until the widget renders:

.. code:: python

    from django_countries.fields import CountryField

    class CustomForm(forms.Form):
        country = CountryField().formfield()

Use ``CountryField(blank=True)`` for non-required form fields, and
``CountryField(blank_label="(Select country)")`` to use a custom label for the
initial blank option.

You can also use the CountrySelectWidget_ as the widget for this field if you
want the flag image after the select box.


Get the countries from Python
=============================

Use the ``django_countries.countries`` object instance as an iterator of ISO
3166-1 country codes and names (sorted by name).

For example:

.. code:: python

    >>> from django_countries import countries
    >>> dict(countries)["NZ"]
    'New Zealand'

    >>> for code, name in list(countries)[:3]:
    ...     print(f"{name} ({code})")
    ...
    Afghanistan (AF)
    Åland Islands (AX)
    Albania (AL)


Template Tags
=============

If you have your country code stored in a different place than a
``CountryField`` you can use the template tag to get a ``Country`` object and
have access to all of its properties:

.. code:: jinja

    {% load countries %}
    {% get_country 'BR' as country %}
    {{ country.name }}

If you need a list of countries, there's also a simple tag for that:

.. code:: jinja

    {% load countries %}
    {% get_countries as countries %}
    <select>
    {% for country in countries %}
        <option value="{{ country.code }}">{{ country.name }}</option>
    {% endfor %}
    </select>


Customization
=============

Customize the country list
--------------------------

Country names are taken from the official ISO 3166-1 list, with some country
names being replaced with their more common usage (such as "Bolivia" instead
of "Bolivia, Plurinational State of").

To retain the official ISO 3166-1 naming for all fields, set the
``COUNTRIES_COMMON_NAMES`` setting to ``False``.

If your project requires the use of alternative names, the inclusion or
exclusion of specific countries then set the ``COUNTRIES_OVERRIDE`` setting to
a dictionary of names which override the defaults. The values can also use a
more `complex dictionary format`_.

Note that you will need to handle translation of customised country names.

Setting a country's name to ``None`` will exclude it from the country list.
For example:

.. code:: python

    from django.utils.translation import gettext_lazy as _

    COUNTRIES_OVERRIDE = {
        "NZ": _("Middle Earth"),
        "AU": None,
        "US": {
            "names": [
                _("United States of America"),
                _("America"),
            ],
        },
    }

If you have a specific list of countries that should be used, use
``COUNTRIES_ONLY``:

.. code:: python

    COUNTRIES_ONLY = ["NZ", "AU"]

or to specify your own country names, use a dictionary or two-tuple list
(string items will use the standard country name):

.. code:: python

    COUNTRIES_ONLY = [
        "US",
        "GB",
        ("NZ", _("Middle Earth")),
        ("AU", _("Desert")),
    ]


Show certain countries first
----------------------------

Provide a list of country codes as the ``COUNTRIES_FIRST`` setting and they
will be shown first in the countries list (in the order specified) before all
the alphanumerically sorted countries.

If you want to sort these initial countries too, set the
``COUNTRIES_FIRST_SORT`` setting to ``True``.

By default, these initial countries are not repeated again in the
alphanumerically sorted list. If you would like them to be repeated, set the
``COUNTRIES_FIRST_REPEAT`` setting to ``True``.

Finally, you can optionally separate these "first" countries with an empty
choice by providing the choice label as the ``COUNTRIES_FIRST_BREAK`` setting.


Customize the flag URL
----------------------

The ``COUNTRIES_FLAG_URL`` setting can be used to set the url for the flag
image assets. It defaults to:

.. code:: python

    COUNTRIES_FLAG_URL = "flags/{code}.gif"

The URL can be relative to the STATIC_URL setting, or an absolute URL.

The location is parsed using Python's string formatting and is passed the
following arguments:

* ``code``
* ``code_upper``

For example: ``COUNTRIES_FLAG_URL = "flags/16x10/{code_upper}.png"``

No checking is done to ensure that a static flag actually exists.

Alternatively, you can specify a different URL on a specific ``CountryField``:

.. code:: python

    class Person(models.Model):
        name = models.CharField(max_length=100)
        country = CountryField(
            countries_flag_url="//flags.example.com/{code}.png")


Single field customization
--------------------------

To customize an individual field, rather than rely on project level settings,
create a ``Countries`` subclass which overrides settings.

To override a setting, give the class an attribute matching the lowercased
setting without the ``COUNTRIES_`` prefix.

Then just reference this class in a field. For example, this ``CountryField``
uses a custom country list that only includes the G8 countries:

.. code:: python

    from django_countries import Countries

    class G8Countries(Countries):
        only = [
            "CA", "FR", "DE", "IT", "JP", "RU", "GB",
            ("EU", _("European Union"))
        ]

    class Vote(models.Model):
        country = CountryField(countries=G8Countries)
        approve = models.BooleanField()


Complex dictionary format
-------------------------

For ``COUNTRIES_ONLY`` and ``COUNTRIES_OVERRIDE``, you can also provide a
dictionary rather than just a translatable string for the country name.

The options within the dictionary are:

``name`` or ``names`` (required)
  Either a single translatable name for this country or a list of multiple
  translatable names. If using multiple names, the first name takes preference
  when using ``COUNTRIES_FIRST`` or the ``Country.name``.

``alpha3`` (optional)
  An ISO 3166-1 three character code (or an empty string to nullify an existing
  code for this country.

``numeric`` (optional)
  An ISO 3166-1 numeric country code (or ``None`` to nullify an existing code
  for this country. The numeric codes 900 to 999 are left available by the
  standard for user-assignment.

``ioc_code`` (optional)
  The country's International Olympic Committee code (or an empty string to
  nullify an existing code).
  

``Country`` object external plugins
-----------------------------------

Other Python packages can add attributes to the Country_ object by using entry
points in their setup script.

.. _Country: `The Country object`_

For example, you could create a ``django_countries_phone`` package which had a
with the following entry point in the ``setup.py`` file. The entry point name
(``phone``) will be the new attribute name on the Country object. The attribute
value will be the return value of the ``get_phone`` function (called with the
Country instance as the sole argument).

.. code:: python

  setup(
      ...
      entry_points={
          "django_countries.Country": "phone = django_countries_phone.get_phone"
      },
      ...
  )



Django Rest Framework
=====================

Django Countries ships with a ``CountryFieldMixin`` to make the
`CountryField`_ model field compatible with DRF serializers. Use the following
mixin with your model serializer:

.. code:: python

    from django_countries.serializers import CountryFieldMixin

    class CountrySerializer(CountryFieldMixin, serializers.ModelSerializer):

        class Meta:
            model = models.Person
            fields = ("name", "email", "country")

This mixin handles both standard and `multi-choice`_ country fields.


Django Rest Framework field
---------------------------

For lower level use (or when not dealing with model fields), you can use the
included ``CountryField`` serializer field. For example:

.. code:: python

    from django_countries.serializer_fields import CountryField

    class CountrySerializer(serializers.Serializer):
        country = CountryField()

You can optionally instantiate the field with the ``countries`` argument to
specify a custom Countries_ instance.

.. _Countries: `Single field customization`_

REST output format
^^^^^^^^^^^^^^^^^^

By default, the field will output just the country code. To output the full
country name instead, instantiate the field with ``name_only=True``.

If you would rather have more verbose output, instantiate the field with
``country_dict=True``, which will result in the field having the following
output structure:

.. code:: json

    {"code": "NZ", "name": "New Zealand"}

Either the code or this dict output structure are acceptable as input
irregardless of the ``country_dict`` argument's value.


OPTIONS request
---------------

When you request OPTIONS against a resource (using the DRF `metadata support`_)
the countries will be returned in the response as choices:

.. code:: text

    OPTIONS /api/address/ HTTP/1.1

    HTTP/1.1 200 OK
    Content-Type: application/json
    Allow: GET, POST, HEAD, OPTIONS

    {
    "actions": {
      "POST": {
        "country": {
        "type": "choice",
        "label": "Country",
        "choices": [
          {
            "display_name": "Australia",
            "value": "AU"
          },
          [...]
          {
            "display_name": "United Kingdom",
            "value": "GB"
          }
        ]
      }
    }

.. _metadata support: http://www.django-rest-framework.org/api-guide/metadata/



GraphQL
=======

A ``Country`` graphene object type is included that can be used when generating
your schema.

.. code:: python

    import graphene
    from graphene_django.types import DjangoObjectType
    from django_countries.graphql.types import Country

    class Person(ObjectType):
        country = graphene.Field(Country)

        class Meta:
            model = models.Person
            fields = ["name", "country"]

The object type has the following fields available:

* ``name`` for the full country name
* ``code`` for the ISO 3166-1 two character country code
* ``alpha3`` for the ISO 3166-1 three character country code
* ``numeric`` for the ISO 3166-1 numeric country code
* ``iocCode`` for the International Olympic Committee country code

==========
Change Log
==========

This log shows interesting changes that happen for each version, latest
versions first. It can be assumed that translations have been updated each
release, and any new translations added.

7.6 (12 February 2024)
======================

- Replace deprecated ``pkg_resources.iter_entry_points`` with
  ``importlib_metadata``.

- Support Django 5.0.

- Support Python 3.12.

7.5.1 (1 February 2023)
=======================

- Make ``CountryField`` queryset filters also work with country codes in
  addition to names.

- Switch to ``pyproject.toml`` rather than ``setup.py`` to fix installation
  issues with pip 23.0+.


7.5 (12 December 2022)
======================

- Rename Turkey to Türkiye.

- A change in v7.4 introduced multi-choice countries being stored sorted and
  deduplicated. This remains the default behaviour going forwards, but these
  can now be overridden via arguments on the ``CountryField``.

- Improve translation fallback handling, fixing a threading race condition that
  could cause odd translation issues. Thanks to Jan Wróblewski and Antoine
  Fontaine for their help in resolving this.
  This also fixes translation issues with older Python 3.6/3.7 versions.

- Add Python 3.11, drop Python 3.6 and Django 2.2 support.


7.4.2 (10 October 2022)
=======================

- Fix error when using ``USE_I18N = False``.


7.4.1 (7 October 2022)
======================

- Fix broken translations due to last common country names fix.


7.4 (7 October 2022)
====================

- Fixed Traditional Chinese translation (needed to be ``locale/zh_Hant``).

- Update flag of Honduras.

- Add Django 4.0 and 4.1 to the test matrix, dropping 3.0 and 3.1

- Add Django Rest Framework 3.13 and 3.14, dropping 3.11.

- Multi-choice countries are now stored sorted and with duplicates stripped.
  Thanks flbraun and Jens Diemer!

- Fix common country names not being honoured in non-English translations (only
  fixed for Python 3.8+).


7.3.2 (4 March 2022)
====================

- Fix slowdown introduced in v7.3 caused by always using country name lookups
  for field comparisons. ``filter(country="New Zealand")`` will no longer match
  now, but instead new ``__name`` and ``__iname`` filters have been added to
  achieve this.


7.3.1 (1 March 2022)
====================

- Typing compatibility fixes for Python <3.9.


7.3 (28 February 2022)
======================

- Make full English country names work in database lookups, for example,
  ``Person.objects.filter(country__icontains="zealand")``.


7.2.1 (11 May 2021)
===================

- Fix Latin translations.


7.2 (10 May 2021)
=================

- Allow the character field to work with custom country codes that are not 2
  characters (such as "GB-WLS").

- Fix compatibility with ``django-migrations-ignore-attrs`` library.


7.1 (17 March 2021)
===================

- Allow customising the ``str_attr`` of Country objects returned from a
  CountryField via a new ``countries_str_attr`` keyword argument (thanks C.
  Quentin).

- Add ``pyuca`` as an extra dependency, so that it can be installed like
  ``pip install django-countries[pyuca]``.

- Add Django 3.2 support.


7.0 (5 December 2020)
=====================

- Add ``name_only`` as an option to the Django Rest Framework serializer field
  (thanks Miguel Marques).

- Add in Python typing.

- Add Python 3.9, Django 3.1, and Django Rest Framework 3.12 support.

- Drop Python 3.5 support.

- Improve IOC code functionality, allowing them to be overridden in
  ``COUNTRIES_OVERRIDE`` using the complex dictionary format.


6.1.3 (18 August 2020)
======================

- Update flag of Mauritania.

- Add flag for Kosovo (under its temporary code of XK).


6.1.2 (26 March 2020)
=====================

- Fix Python 3.5 syntax error (no f-strings just yet...).


6.1.1 (26 March 2020)
=====================

- Change ISO country import so that "Falkland Islands  [Malvinas]" => "Falkland Islands (Malvinas)".


6.1 (20 March 2020)
===================

- Add a GraphQL object type for a django ``Country`` object.


6.0 (28 February 2020)
======================

- Make DRF CountryField respect ``blank=False``. This is a backwards incompatible change since blank input will now
  return a validation error (unless ``blank`` is explicitly set to ``True``).

- Fix ``COUNTRIES_OVERRIDE`` when using the complex dictionary format and a single name.

- Add bandit to the test suite for basic security analysis.

- Drop Python 2.7 and Python 3.4 support.

- Add Rest Framework 3.10 and 3.11 to the test matrix, remove 3.8.

- Fix a memory leak when using PyUCA. Thanks Meiyer (aka interDist)!


5.5 (11 September 2019)
=======================

- Django 3.0 compatibility.

- Plugin system for extending the ``Country`` object.


5.4 (11 August 2019)
====================

- Renamed Macedonia -> North Macedonia.

- Fix an outlying ``makemigrations`` error.

- Pulled in new translations which were provided but missing from previous
  version.

- Fixed Simplified Chinese translation (needed to be ``locale/zh_Hans``).

- Introduce an optional complex format for ``COUNTRIES_ONLY`` and
  ``COUNTRIES_OVERRIDE`` to allow for multiple names for a country, a custom
  three character code, and a custom numeric country code.


5.3.3 (16 February 2019)
========================

- Add test coverage for Django Rest Framework 3.9.


5.3.2 (27 August 2018)
======================

- Tests for Django 2.1 and Django Rest Framework 3.8.


5.3.1 (12 June 2018)
====================

- Fix ``dumpdata`` and ``loaddata`` for ``CountryField(multiple=True)``.


5.3 (20 April 2018)
===================

- Iterating a ``Countries`` object now returns named tuples. This makes things
  nicer when using ``{% get_countries %}`` or using the country list elsewhere
  in your code.


5.2 (9 March 2018)
==================

- Ensure Django 2.1 compatibility for ``CountrySelectWidget``.

- Fix regression introduced into 5.1 when using Django 1.8 and certain queryset
  lookup types (like ``__in``).


5.1.1 (31 January 2018)
=======================

- Fix some translations that were included in 5.1 but not compiled.


5.1 (30 January 2018)
=====================

* Tests now also cover Django Rest Framework 3.7 and Django 2.0.

* Allow for creating country fields using (valid) alpha-3 or numeric codes.

* Fix migration error with blank default (thanks Jens Diemer).

* Add a ``{% get_countries %}`` template tag (thanks Matija Čvrk).


5.0 (10 October 2017)
=====================

* No longer allow ``multiple=True`` and ``null=True`` together. This causes
  problems saving the field, and ``null`` shouldn't really be used anyway
  because the country field is a subclass of ``CharField``.


4.6 (16 June 2017)
==================

* Add a ``CountryFieldMixin`` Django Rest Framework serializer mixin that
  automatically picks the right field type for a ``CountryField`` (both single
  and multi-choice).

* Validation for Django Rest Framework field (thanks Simon Meers).

* Allow case-insensitive ``.by_name()`` matching (thanks again, Simon).

* Ensure a multiple-choice ``CountryField.max_length`` is enough to hold all
  countries.

* Fix inefficient pickling of countries (thanks Craig de Stigter for the report
  and tests).

* Stop adding a blank choice when dealing with a multi-choice ``CountryField``.

* Tests now cover multiple Django Rest Framework versions (back to 3.3).

4.6.1
-----

* Fix invalid reStructuredText in CHANGES.

4.6.2
-----

* Use transparency layer for flag sprites.


4.5 (18 April 2017)
===================

* Change rest framework field to be based on ``ChoiceField``.

* Allow for the rest framework field to deserialize by full country name
  (specifically the English name for now).


4.4 (6 April 2017)
==================

* Fix for broken CountryField on certain models in Django 1.11.
  Thanks aktiur for the test case.

* Update tests to cover Django 1.11


4.3 (29 March 2017)
===================

* Handle "Czechia" translations in a nicer way (fall back to "Czech Republic"
  until new translations are available).

* Fix for an import error in Django 1.9+ due to use of non-lazy ``ugettext`` in
  the django-countries custom admin filter.

* Back to 100% test coverage.


4.2 (10 March 2017)
===================

* Add sprite flag files (and ``Country.flag_css`` property) to help minimize
  HTTP requests.


4.1 (22 February 2017)
======================

* Better default Django admin filter when filtering a country field in a
  ``ModelAdmin``.

* Fix settings to support Django 1.11

* Fix when using a model instance with a deferred country field.

* Allow ``CountryField`` to handle multiple countries at once!

* Allow CountryField to still work if Deferred.

* Fix a field with customized country list. Thanks pilmie!


4.0 (16 August 2016)
====================

Django supported versions are now 1.8+

* Drop legacy code

* Fix tests, 100% coverage

* IOS / OSX unicode flags function

* Fix widget choices on Django 1.9+

* Add ``COUNTRIES_FIRST_SORT``. Thanks Edraak!

4.0.1
-----

* Fix tests for ``COUNTRIES_FIRST_SORT`` (feature still worked, tests didn't).


3.4 (22 October 2015)
=====================

* Extend test suite to cover Django 1.8

* Fix XSS escaping issue in CountrySelectWidget

* Common name changes: fix typo of Moldova, add United Kingdom

* Add ``{% get_country %}`` template tag.

* New ``CountryField`` Django Rest Framework serializer field.

3.4.1
-----

* Fix minor packaging error.


3.3 (30 Mar 2015)
=================

* Add the attributes to ``Countries`` class that can override the default
  settings.

* CountriesField can now be passed a custom countries subclass to use, which
  combined with the previous change allows for different country choices for
  different fields.

* Allow ``COUNTRIES_ONLY`` to also accept just country codes in its list
  (rather than only two-tuples), looking up the translatable country name from
  the full country list.

* Fix Montenegro flag size (was 12px high rather than the standard 11px).

* Fix outdated ISO country name formatting for Bolivia, Gambia, Holy See,
  Iran, Micronesia, and Venezuela.


3.2 (24 Feb 2015)
=================

* Fixes initial iteration failing for a fresh ``Countries`` object.

* Fix widget's flag URLs (and use ensure widget is HTML encoded safely).

* Add ``countries.by_name(country, language='en')`` method, allowing lookup of
  a country code by its full country name. Thanks Josh Schneier.


3.1 (15 Jan 2015)
=================

* Start change log :)

* Add a ``COUNTRIES_FIRST`` setting (and some other related ones) to allow for
  specific countries to be shown before the entire alphanumeric list.

* Add a ``blank_label`` argument to ``CountryField`` to allow customization of
  the label shown in the initial blank choice shown in the select widget.

3.1.1 (15 Jan 2015)
-------------------

* Packaging fix (``CHANGES.rst`` wasn't in the manifest)


3.0 (22 Oct 2014)
=================

Django supported versions are now 1.4 (LTS) and 1.6+

* Add ``COUNTRIES_ONLY`` setting to restrict to a specific list of countries.

* Optimize country name translations to avoid exessive translation calls that
  were causing a notable performance impact.

* PyUCA integration, allowing for more accurate sorting across all locales.
  Also, a better sorting method when PyUCA isn't installed.

* Better tests (now at 100% test coverage).

* Add a ``COUNTRIES_FLAG_URL`` setting to allow custom flag urls.

* Support both IOC and numeric country codes, allowing more flexible lookup of
  countries and specific code types.

* Field descriptor now returns ``None`` if no country matches (*reverted in
  v3.0.1*)

3.0.1 (27 Oct 2014)
-------------------

* Revert descriptor to always return a Country object.

* Fix the ``CountryField`` widget choices appearing empty due to a translation
  change in v3.0.

3.0.2 (29 Dec 2014)
-------------------

* Fix ``CountrySelectWidget`` failing when used with a model form that is
  passed a model instance.


2.1 (24 Mar 2014)
=================

* Add IOC (3 letter) country codes.

* Fix bug when loading fixtures.

2.1.1 (28 Mar 2014)
-------------------

* Fix issue with translations getting evaluated early.

2.1.2 (28 Mar 2014)
-------------------

* Fix Python 3 compatibility.



2.0 (18 Feb 2014)
=================

This is the first entry to the change log. The previous was 1.5,
released 19 Nov 2012.

* Optimized flag images, adding flags missing from original source.

* Better storage of settings and country list.

* New country list format for fields.

* Better tests.

* Changed ``COUNTRIES_FLAG_STATIC`` setting to ``COUNTRIES_FLAG_URL``.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SmileyChris/django-countries/",
    "name": "django-countryfield",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,countries,flags",
    "author": "Chris Beaven",
    "author_email": "smileychris@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cb/c2/2ab109183ef724de43faf3693d91b3edeefff1ddac59c78b51cbad52cc3b/django-countryfield-7.6.tar.gz",
    "platform": null,
    "description": "================\nDjango Countries\n================\n\n.. image:: https://badge.fury.io/py/django-countries.svg\n    :alt: PyPI version\n    :target: https://badge.fury.io/py/django-countries\n\n.. image:: https://github.com/SmileyChris/django-countries/actions/workflows/tests.yml/badge.svg\n    :alt: Build status\n    :target: https://github.com/SmileyChris/django-countries/actions/workflows/tests.yml\n\nA Django application that provides country choices for use with forms, flag\nicons static files, and a country field for models.\n\nCountry names are translated using Django's standard ``gettext``. If you would\nlike to help by adding a translation, please visit\nhttps://www.transifex.com/smileychris/django-countries/\n\n\n.. contents::\n    :local:\n    :backlinks: none\n\n\nInstallation\n============\n\n1. ``pip install django-countries``\n\n   For more accurate sorting of translated country names, install it with the\n   optional pyuca_ package:\n\n   ``pip install django-countries[pyuca]``\n\n2. Add ``django_countries`` to ``INSTALLED_APPS``\n\n.. _pyuca: https://pypi.python.org/pypi/pyuca/\n\n\nCountryField\n============\n\nA country field for Django models that provides all ISO 3166-1 countries as\nchoices.\n\n``CountryField`` is based on Django's ``CharField``, providing choices\ncorresponding to the official ISO 3166-1 list of countries (with a default\n``max_length`` of 2).\n\nConsider the following model using a ``CountryField``:\n\n.. code:: python\n\n    from django.db import models\n    from django_countries.fields import CountryField\n\n    class Person(models.Model):\n        name = models.CharField(max_length=100)\n        country = CountryField()\n\nAny ``Person`` instance will have a ``country`` attribute that you can use to\nget details of the person's country:\n\n.. code:: python\n\n    >>> person = Person(name=\"Chris\", country=\"NZ\")\n    >>> person.country\n    Country(code='NZ')\n    >>> person.country.name\n    'New Zealand'\n    >>> person.country.flag\n    '/static/flags/nz.gif'\n\nThis object (``person.country`` in the example) is a ``Country`` instance,\nwhich is described below.\n\nUse ``blank_label`` to set the label for the initial blank choice shown in\nforms:\n\n.. code:: python\n\n    country = CountryField(blank_label=\"(select country)\")\n\nYou can filter using the full English country names in addition to country\ncodes, even though only the country codes are stored in the database by using\nthe queryset lookups ``contains``, ``startswith``, ``endswith``, ``regex``, or\ntheir case insensitive versions. Use ``__name`` or ``__iname`` for the\n``exact``/``iexact`` equivalent:\n\n.. code:: python\n\n    >>> Person.objects.filter(country__name=\"New Zealand\").count()\n    1\n    >>> Person.objects.filter(country__icontains=\"zealand\").count()\n    1\n\n\nMulti-choice\n------------\n\nThis field can also allow multiple selections of countries (saved as a comma\nseparated string). The field will always output a list of countries in this\nmode. For example:\n\n.. code:: python\n\n    class Incident(models.Model):\n        title = models.CharField(max_length=100)\n        countries = CountryField(multiple=True)\n\n    >>> for country in Incident.objects.get(title=\"Pavlova dispute\").countries:\n    ...     print(country.name)\n    Australia\n    New Zealand\n\nBy default, countries are stored sorted for data consistency, and any\nduplicates are removed. These behaviours can be overridden by using the field\narguments ``multiple_sort=False`` and ``multiple_unique=False`` respectively.\n\n\nThe ``Country`` object\n----------------------\n\nAn object used to represent a country, instantiated with a two character\ncountry code, three character code, or numeric code.\n\nIt can be compared to other objects as if it was a string containing the\ncountry code and when evaluated as text, returns the country code.\n\nname\n  Contains the full country name.\n\nflag\n  Contains a URL to the flag. If you page could have lots of different flags\n  then consider using ``flag_css`` instead to avoid excessive HTTP requests.\n\nflag_css\n  Output the css classes needed to display an HTML element as the correct flag\n  from within a single sprite image that contains all flags. For example:\n\n  .. code:: jinja\n\n    <link rel=\"stylesheet\" href=\"{% static 'flags/sprite.css' %}\">\n    <i class=\"{{ country.flag_css }}\"></i>\n\n  For multiple flag resolutions, use ``sprite-hq.css`` instead and add the\n  ``flag2x``, ``flag3x``, or ``flag4x`` class. For example:\n\n  .. code:: jinja\n\n    <link rel=\"stylesheet\" href=\"{% static 'flags/sprite-hq.css' %}\">\n    Normal: <i class=\"{{ country.flag_css }}\"></i>\n    Bigger: <i class=\"flag2x {{ country.flag_css }}\"></i>\n\n  You might also want to consider using ``aria-label`` for better\n  accessibility:\n\n  .. code:: jinja\n\n    <i class=\"{{ country.flag_css }}\"\n        aria-label=\"{% blocktrans with country_code=country.code %}\n            {{ country_code }} flag\n        {% endblocktrans %}\"></i>\n\nunicode_flag\n  A unicode glyph for the flag for this country. Currently well-supported in\n  iOS and OS X. See https://en.wikipedia.org/wiki/Regional_Indicator_Symbol\n  for details.\n\ncode\n  The two letter country code for this country.\n\nalpha3\n  The three letter country code for this country.\n\nnumeric\n  The numeric country code for this country (as an integer).\n\nnumeric_padded\n  The numeric country code as a three character 0-padded string.\n\nioc_code\n  The three letter International Olympic Committee country code.\n\n\n``CountrySelectWidget``\n-----------------------\n\nA widget is included that can show the flag image after the select box\n(updated with JavaScript when the selection changes).\n\nWhen you create your form, you can use this custom widget like normal:\n\n.. code:: python\n\n    from django_countries.widgets import CountrySelectWidget\n\n    class PersonForm(forms.ModelForm):\n        class Meta:\n            model = models.Person\n            fields = (\"name\", \"country\")\n            widgets = {\"country\": CountrySelectWidget()}\n\nPass a ``layout`` text argument to the widget to change the positioning of the\nflag and widget. The default layout is:\n\n.. code:: python\n\n    '{widget}<img class=\"country-select-flag\" id=\"{flag_id}\" style=\"margin: 6px 4px 0\" src=\"{country.flag}\">'\n\n\nCustom forms\n============\n\nIf you want to use the countries in a custom form, use the model field's custom\nform field to ensure the translatable strings for the country choices are left\nlazy until the widget renders:\n\n.. code:: python\n\n    from django_countries.fields import CountryField\n\n    class CustomForm(forms.Form):\n        country = CountryField().formfield()\n\nUse ``CountryField(blank=True)`` for non-required form fields, and\n``CountryField(blank_label=\"(Select country)\")`` to use a custom label for the\ninitial blank option.\n\nYou can also use the CountrySelectWidget_ as the widget for this field if you\nwant the flag image after the select box.\n\n\nGet the countries from Python\n=============================\n\nUse the ``django_countries.countries`` object instance as an iterator of ISO\n3166-1 country codes and names (sorted by name).\n\nFor example:\n\n.. code:: python\n\n    >>> from django_countries import countries\n    >>> dict(countries)[\"NZ\"]\n    'New Zealand'\n\n    >>> for code, name in list(countries)[:3]:\n    ...     print(f\"{name} ({code})\")\n    ...\n    Afghanistan (AF)\n    \u00c5land Islands (AX)\n    Albania (AL)\n\n\nTemplate Tags\n=============\n\nIf you have your country code stored in a different place than a\n``CountryField`` you can use the template tag to get a ``Country`` object and\nhave access to all of its properties:\n\n.. code:: jinja\n\n    {% load countries %}\n    {% get_country 'BR' as country %}\n    {{ country.name }}\n\nIf you need a list of countries, there's also a simple tag for that:\n\n.. code:: jinja\n\n    {% load countries %}\n    {% get_countries as countries %}\n    <select>\n    {% for country in countries %}\n        <option value=\"{{ country.code }}\">{{ country.name }}</option>\n    {% endfor %}\n    </select>\n\n\nCustomization\n=============\n\nCustomize the country list\n--------------------------\n\nCountry names are taken from the official ISO 3166-1 list, with some country\nnames being replaced with their more common usage (such as \"Bolivia\" instead\nof \"Bolivia, Plurinational State of\").\n\nTo retain the official ISO 3166-1 naming for all fields, set the\n``COUNTRIES_COMMON_NAMES`` setting to ``False``.\n\nIf your project requires the use of alternative names, the inclusion or\nexclusion of specific countries then set the ``COUNTRIES_OVERRIDE`` setting to\na dictionary of names which override the defaults. The values can also use a\nmore `complex dictionary format`_.\n\nNote that you will need to handle translation of customised country names.\n\nSetting a country's name to ``None`` will exclude it from the country list.\nFor example:\n\n.. code:: python\n\n    from django.utils.translation import gettext_lazy as _\n\n    COUNTRIES_OVERRIDE = {\n        \"NZ\": _(\"Middle Earth\"),\n        \"AU\": None,\n        \"US\": {\n            \"names\": [\n                _(\"United States of America\"),\n                _(\"America\"),\n            ],\n        },\n    }\n\nIf you have a specific list of countries that should be used, use\n``COUNTRIES_ONLY``:\n\n.. code:: python\n\n    COUNTRIES_ONLY = [\"NZ\", \"AU\"]\n\nor to specify your own country names, use a dictionary or two-tuple list\n(string items will use the standard country name):\n\n.. code:: python\n\n    COUNTRIES_ONLY = [\n        \"US\",\n        \"GB\",\n        (\"NZ\", _(\"Middle Earth\")),\n        (\"AU\", _(\"Desert\")),\n    ]\n\n\nShow certain countries first\n----------------------------\n\nProvide a list of country codes as the ``COUNTRIES_FIRST`` setting and they\nwill be shown first in the countries list (in the order specified) before all\nthe alphanumerically sorted countries.\n\nIf you want to sort these initial countries too, set the\n``COUNTRIES_FIRST_SORT`` setting to ``True``.\n\nBy default, these initial countries are not repeated again in the\nalphanumerically sorted list. If you would like them to be repeated, set the\n``COUNTRIES_FIRST_REPEAT`` setting to ``True``.\n\nFinally, you can optionally separate these \"first\" countries with an empty\nchoice by providing the choice label as the ``COUNTRIES_FIRST_BREAK`` setting.\n\n\nCustomize the flag URL\n----------------------\n\nThe ``COUNTRIES_FLAG_URL`` setting can be used to set the url for the flag\nimage assets. It defaults to:\n\n.. code:: python\n\n    COUNTRIES_FLAG_URL = \"flags/{code}.gif\"\n\nThe URL can be relative to the STATIC_URL setting, or an absolute URL.\n\nThe location is parsed using Python's string formatting and is passed the\nfollowing arguments:\n\n* ``code``\n* ``code_upper``\n\nFor example: ``COUNTRIES_FLAG_URL = \"flags/16x10/{code_upper}.png\"``\n\nNo checking is done to ensure that a static flag actually exists.\n\nAlternatively, you can specify a different URL on a specific ``CountryField``:\n\n.. code:: python\n\n    class Person(models.Model):\n        name = models.CharField(max_length=100)\n        country = CountryField(\n            countries_flag_url=\"//flags.example.com/{code}.png\")\n\n\nSingle field customization\n--------------------------\n\nTo customize an individual field, rather than rely on project level settings,\ncreate a ``Countries`` subclass which overrides settings.\n\nTo override a setting, give the class an attribute matching the lowercased\nsetting without the ``COUNTRIES_`` prefix.\n\nThen just reference this class in a field. For example, this ``CountryField``\nuses a custom country list that only includes the G8 countries:\n\n.. code:: python\n\n    from django_countries import Countries\n\n    class G8Countries(Countries):\n        only = [\n            \"CA\", \"FR\", \"DE\", \"IT\", \"JP\", \"RU\", \"GB\",\n            (\"EU\", _(\"European Union\"))\n        ]\n\n    class Vote(models.Model):\n        country = CountryField(countries=G8Countries)\n        approve = models.BooleanField()\n\n\nComplex dictionary format\n-------------------------\n\nFor ``COUNTRIES_ONLY`` and ``COUNTRIES_OVERRIDE``, you can also provide a\ndictionary rather than just a translatable string for the country name.\n\nThe options within the dictionary are:\n\n``name`` or ``names`` (required)\n  Either a single translatable name for this country or a list of multiple\n  translatable names. If using multiple names, the first name takes preference\n  when using ``COUNTRIES_FIRST`` or the ``Country.name``.\n\n``alpha3`` (optional)\n  An ISO 3166-1 three character code (or an empty string to nullify an existing\n  code for this country.\n\n``numeric`` (optional)\n  An ISO 3166-1 numeric country code (or ``None`` to nullify an existing code\n  for this country. The numeric codes 900 to 999 are left available by the\n  standard for user-assignment.\n\n``ioc_code`` (optional)\n  The country's International Olympic Committee code (or an empty string to\n  nullify an existing code).\n  \n\n``Country`` object external plugins\n-----------------------------------\n\nOther Python packages can add attributes to the Country_ object by using entry\npoints in their setup script.\n\n.. _Country: `The Country object`_\n\nFor example, you could create a ``django_countries_phone`` package which had a\nwith the following entry point in the ``setup.py`` file. The entry point name\n(``phone``) will be the new attribute name on the Country object. The attribute\nvalue will be the return value of the ``get_phone`` function (called with the\nCountry instance as the sole argument).\n\n.. code:: python\n\n  setup(\n      ...\n      entry_points={\n          \"django_countries.Country\": \"phone = django_countries_phone.get_phone\"\n      },\n      ...\n  )\n\n\n\nDjango Rest Framework\n=====================\n\nDjango Countries ships with a ``CountryFieldMixin`` to make the\n`CountryField`_ model field compatible with DRF serializers. Use the following\nmixin with your model serializer:\n\n.. code:: python\n\n    from django_countries.serializers import CountryFieldMixin\n\n    class CountrySerializer(CountryFieldMixin, serializers.ModelSerializer):\n\n        class Meta:\n            model = models.Person\n            fields = (\"name\", \"email\", \"country\")\n\nThis mixin handles both standard and `multi-choice`_ country fields.\n\n\nDjango Rest Framework field\n---------------------------\n\nFor lower level use (or when not dealing with model fields), you can use the\nincluded ``CountryField`` serializer field. For example:\n\n.. code:: python\n\n    from django_countries.serializer_fields import CountryField\n\n    class CountrySerializer(serializers.Serializer):\n        country = CountryField()\n\nYou can optionally instantiate the field with the ``countries`` argument to\nspecify a custom Countries_ instance.\n\n.. _Countries: `Single field customization`_\n\nREST output format\n^^^^^^^^^^^^^^^^^^\n\nBy default, the field will output just the country code. To output the full\ncountry name instead, instantiate the field with ``name_only=True``.\n\nIf you would rather have more verbose output, instantiate the field with\n``country_dict=True``, which will result in the field having the following\noutput structure:\n\n.. code:: json\n\n    {\"code\": \"NZ\", \"name\": \"New Zealand\"}\n\nEither the code or this dict output structure are acceptable as input\nirregardless of the ``country_dict`` argument's value.\n\n\nOPTIONS request\n---------------\n\nWhen you request OPTIONS against a resource (using the DRF `metadata support`_)\nthe countries will be returned in the response as choices:\n\n.. code:: text\n\n    OPTIONS /api/address/ HTTP/1.1\n\n    HTTP/1.1 200 OK\n    Content-Type: application/json\n    Allow: GET, POST, HEAD, OPTIONS\n\n    {\n    \"actions\": {\n      \"POST\": {\n        \"country\": {\n        \"type\": \"choice\",\n        \"label\": \"Country\",\n        \"choices\": [\n          {\n            \"display_name\": \"Australia\",\n            \"value\": \"AU\"\n          },\n          [...]\n          {\n            \"display_name\": \"United Kingdom\",\n            \"value\": \"GB\"\n          }\n        ]\n      }\n    }\n\n.. _metadata support: http://www.django-rest-framework.org/api-guide/metadata/\n\n\n\nGraphQL\n=======\n\nA ``Country`` graphene object type is included that can be used when generating\nyour schema.\n\n.. code:: python\n\n    import graphene\n    from graphene_django.types import DjangoObjectType\n    from django_countries.graphql.types import Country\n\n    class Person(ObjectType):\n        country = graphene.Field(Country)\n\n        class Meta:\n            model = models.Person\n            fields = [\"name\", \"country\"]\n\nThe object type has the following fields available:\n\n* ``name`` for the full country name\n* ``code`` for the ISO 3166-1 two character country code\n* ``alpha3`` for the ISO 3166-1 three character country code\n* ``numeric`` for the ISO 3166-1 numeric country code\n* ``iocCode`` for the International Olympic Committee country code\n\n==========\nChange Log\n==========\n\nThis log shows interesting changes that happen for each version, latest\nversions first. It can be assumed that translations have been updated each\nrelease, and any new translations added.\n\n7.6 (12 February 2024)\n======================\n\n- Replace deprecated ``pkg_resources.iter_entry_points`` with\n  ``importlib_metadata``.\n\n- Support Django 5.0.\n\n- Support Python 3.12.\n\n7.5.1 (1 February 2023)\n=======================\n\n- Make ``CountryField`` queryset filters also work with country codes in\n  addition to names.\n\n- Switch to ``pyproject.toml`` rather than ``setup.py`` to fix installation\n  issues with pip 23.0+.\n\n\n7.5 (12 December 2022)\n======================\n\n- Rename Turkey to T\u00fcrkiye.\n\n- A change in v7.4 introduced multi-choice countries being stored sorted and\n  deduplicated. This remains the default behaviour going forwards, but these\n  can now be overridden via arguments on the ``CountryField``.\n\n- Improve translation fallback handling, fixing a threading race condition that\n  could cause odd translation issues. Thanks to Jan Wr\u00f3blewski and Antoine\n  Fontaine for their help in resolving this.\n  This also fixes translation issues with older Python 3.6/3.7 versions.\n\n- Add Python 3.11, drop Python 3.6 and Django 2.2 support.\n\n\n7.4.2 (10 October 2022)\n=======================\n\n- Fix error when using ``USE_I18N = False``.\n\n\n7.4.1 (7 October 2022)\n======================\n\n- Fix broken translations due to last common country names fix.\n\n\n7.4 (7 October 2022)\n====================\n\n- Fixed Traditional Chinese translation (needed to be ``locale/zh_Hant``).\n\n- Update flag of Honduras.\n\n- Add Django 4.0 and 4.1 to the test matrix, dropping 3.0 and 3.1\n\n- Add Django Rest Framework 3.13 and 3.14, dropping 3.11.\n\n- Multi-choice countries are now stored sorted and with duplicates stripped.\n  Thanks flbraun and Jens Diemer!\n\n- Fix common country names not being honoured in non-English translations (only\n  fixed for Python 3.8+).\n\n\n7.3.2 (4 March 2022)\n====================\n\n- Fix slowdown introduced in v7.3 caused by always using country name lookups\n  for field comparisons. ``filter(country=\"New Zealand\")`` will no longer match\n  now, but instead new ``__name`` and ``__iname`` filters have been added to\n  achieve this.\n\n\n7.3.1 (1 March 2022)\n====================\n\n- Typing compatibility fixes for Python <3.9.\n\n\n7.3 (28 February 2022)\n======================\n\n- Make full English country names work in database lookups, for example,\n  ``Person.objects.filter(country__icontains=\"zealand\")``.\n\n\n7.2.1 (11 May 2021)\n===================\n\n- Fix Latin translations.\n\n\n7.2 (10 May 2021)\n=================\n\n- Allow the character field to work with custom country codes that are not 2\n  characters (such as \"GB-WLS\").\n\n- Fix compatibility with ``django-migrations-ignore-attrs`` library.\n\n\n7.1 (17 March 2021)\n===================\n\n- Allow customising the ``str_attr`` of Country objects returned from a\n  CountryField via a new ``countries_str_attr`` keyword argument (thanks C.\n  Quentin).\n\n- Add ``pyuca`` as an extra dependency, so that it can be installed like\n  ``pip install django-countries[pyuca]``.\n\n- Add Django 3.2 support.\n\n\n7.0 (5 December 2020)\n=====================\n\n- Add ``name_only`` as an option to the Django Rest Framework serializer field\n  (thanks Miguel Marques).\n\n- Add in Python typing.\n\n- Add Python 3.9, Django 3.1, and Django Rest Framework 3.12 support.\n\n- Drop Python 3.5 support.\n\n- Improve IOC code functionality, allowing them to be overridden in\n  ``COUNTRIES_OVERRIDE`` using the complex dictionary format.\n\n\n6.1.3 (18 August 2020)\n======================\n\n- Update flag of Mauritania.\n\n- Add flag for Kosovo (under its temporary code of XK).\n\n\n6.1.2 (26 March 2020)\n=====================\n\n- Fix Python 3.5 syntax error (no f-strings just yet...).\n\n\n6.1.1 (26 March 2020)\n=====================\n\n- Change ISO country import so that \"Falkland Islands  [Malvinas]\" => \"Falkland Islands (Malvinas)\".\n\n\n6.1 (20 March 2020)\n===================\n\n- Add a GraphQL object type for a django ``Country`` object.\n\n\n6.0 (28 February 2020)\n======================\n\n- Make DRF CountryField respect ``blank=False``. This is a backwards incompatible change since blank input will now\n  return a validation error (unless ``blank`` is explicitly set to ``True``).\n\n- Fix ``COUNTRIES_OVERRIDE`` when using the complex dictionary format and a single name.\n\n- Add bandit to the test suite for basic security analysis.\n\n- Drop Python 2.7 and Python 3.4 support.\n\n- Add Rest Framework 3.10 and 3.11 to the test matrix, remove 3.8.\n\n- Fix a memory leak when using PyUCA. Thanks Meiyer (aka interDist)!\n\n\n5.5 (11 September 2019)\n=======================\n\n- Django 3.0 compatibility.\n\n- Plugin system for extending the ``Country`` object.\n\n\n5.4 (11 August 2019)\n====================\n\n- Renamed Macedonia -> North Macedonia.\n\n- Fix an outlying ``makemigrations`` error.\n\n- Pulled in new translations which were provided but missing from previous\n  version.\n\n- Fixed Simplified Chinese translation (needed to be ``locale/zh_Hans``).\n\n- Introduce an optional complex format for ``COUNTRIES_ONLY`` and\n  ``COUNTRIES_OVERRIDE`` to allow for multiple names for a country, a custom\n  three character code, and a custom numeric country code.\n\n\n5.3.3 (16 February 2019)\n========================\n\n- Add test coverage for Django Rest Framework 3.9.\n\n\n5.3.2 (27 August 2018)\n======================\n\n- Tests for Django 2.1 and Django Rest Framework 3.8.\n\n\n5.3.1 (12 June 2018)\n====================\n\n- Fix ``dumpdata`` and ``loaddata`` for ``CountryField(multiple=True)``.\n\n\n5.3 (20 April 2018)\n===================\n\n- Iterating a ``Countries`` object now returns named tuples. This makes things\n  nicer when using ``{% get_countries %}`` or using the country list elsewhere\n  in your code.\n\n\n5.2 (9 March 2018)\n==================\n\n- Ensure Django 2.1 compatibility for ``CountrySelectWidget``.\n\n- Fix regression introduced into 5.1 when using Django 1.8 and certain queryset\n  lookup types (like ``__in``).\n\n\n5.1.1 (31 January 2018)\n=======================\n\n- Fix some translations that were included in 5.1 but not compiled.\n\n\n5.1 (30 January 2018)\n=====================\n\n* Tests now also cover Django Rest Framework 3.7 and Django 2.0.\n\n* Allow for creating country fields using (valid) alpha-3 or numeric codes.\n\n* Fix migration error with blank default (thanks Jens Diemer).\n\n* Add a ``{% get_countries %}`` template tag (thanks Matija \u010cvrk).\n\n\n5.0 (10 October 2017)\n=====================\n\n* No longer allow ``multiple=True`` and ``null=True`` together. This causes\n  problems saving the field, and ``null`` shouldn't really be used anyway\n  because the country field is a subclass of ``CharField``.\n\n\n4.6 (16 June 2017)\n==================\n\n* Add a ``CountryFieldMixin`` Django Rest Framework serializer mixin that\n  automatically picks the right field type for a ``CountryField`` (both single\n  and multi-choice).\n\n* Validation for Django Rest Framework field (thanks Simon Meers).\n\n* Allow case-insensitive ``.by_name()`` matching (thanks again, Simon).\n\n* Ensure a multiple-choice ``CountryField.max_length`` is enough to hold all\n  countries.\n\n* Fix inefficient pickling of countries (thanks Craig de Stigter for the report\n  and tests).\n\n* Stop adding a blank choice when dealing with a multi-choice ``CountryField``.\n\n* Tests now cover multiple Django Rest Framework versions (back to 3.3).\n\n4.6.1\n-----\n\n* Fix invalid reStructuredText in CHANGES.\n\n4.6.2\n-----\n\n* Use transparency layer for flag sprites.\n\n\n4.5 (18 April 2017)\n===================\n\n* Change rest framework field to be based on ``ChoiceField``.\n\n* Allow for the rest framework field to deserialize by full country name\n  (specifically the English name for now).\n\n\n4.4 (6 April 2017)\n==================\n\n* Fix for broken CountryField on certain models in Django 1.11.\n  Thanks aktiur for the test case.\n\n* Update tests to cover Django 1.11\n\n\n4.3 (29 March 2017)\n===================\n\n* Handle \"Czechia\" translations in a nicer way (fall back to \"Czech Republic\"\n  until new translations are available).\n\n* Fix for an import error in Django 1.9+ due to use of non-lazy ``ugettext`` in\n  the django-countries custom admin filter.\n\n* Back to 100% test coverage.\n\n\n4.2 (10 March 2017)\n===================\n\n* Add sprite flag files (and ``Country.flag_css`` property) to help minimize\n  HTTP requests.\n\n\n4.1 (22 February 2017)\n======================\n\n* Better default Django admin filter when filtering a country field in a\n  ``ModelAdmin``.\n\n* Fix settings to support Django 1.11\n\n* Fix when using a model instance with a deferred country field.\n\n* Allow ``CountryField`` to handle multiple countries at once!\n\n* Allow CountryField to still work if Deferred.\n\n* Fix a field with customized country list. Thanks pilmie!\n\n\n4.0 (16 August 2016)\n====================\n\nDjango supported versions are now 1.8+\n\n* Drop legacy code\n\n* Fix tests, 100% coverage\n\n* IOS / OSX unicode flags function\n\n* Fix widget choices on Django 1.9+\n\n* Add ``COUNTRIES_FIRST_SORT``. Thanks Edraak!\n\n4.0.1\n-----\n\n* Fix tests for ``COUNTRIES_FIRST_SORT`` (feature still worked, tests didn't).\n\n\n3.4 (22 October 2015)\n=====================\n\n* Extend test suite to cover Django 1.8\n\n* Fix XSS escaping issue in CountrySelectWidget\n\n* Common name changes: fix typo of Moldova, add United Kingdom\n\n* Add ``{% get_country %}`` template tag.\n\n* New ``CountryField`` Django Rest Framework serializer field.\n\n3.4.1\n-----\n\n* Fix minor packaging error.\n\n\n3.3 (30 Mar 2015)\n=================\n\n* Add the attributes to ``Countries`` class that can override the default\n  settings.\n\n* CountriesField can now be passed a custom countries subclass to use, which\n  combined with the previous change allows for different country choices for\n  different fields.\n\n* Allow ``COUNTRIES_ONLY`` to also accept just country codes in its list\n  (rather than only two-tuples), looking up the translatable country name from\n  the full country list.\n\n* Fix Montenegro flag size (was 12px high rather than the standard 11px).\n\n* Fix outdated ISO country name formatting for Bolivia, Gambia, Holy See,\n  Iran, Micronesia, and Venezuela.\n\n\n3.2 (24 Feb 2015)\n=================\n\n* Fixes initial iteration failing for a fresh ``Countries`` object.\n\n* Fix widget's flag URLs (and use ensure widget is HTML encoded safely).\n\n* Add ``countries.by_name(country, language='en')`` method, allowing lookup of\n  a country code by its full country name. Thanks Josh Schneier.\n\n\n3.1 (15 Jan 2015)\n=================\n\n* Start change log :)\n\n* Add a ``COUNTRIES_FIRST`` setting (and some other related ones) to allow for\n  specific countries to be shown before the entire alphanumeric list.\n\n* Add a ``blank_label`` argument to ``CountryField`` to allow customization of\n  the label shown in the initial blank choice shown in the select widget.\n\n3.1.1 (15 Jan 2015)\n-------------------\n\n* Packaging fix (``CHANGES.rst`` wasn't in the manifest)\n\n\n3.0 (22 Oct 2014)\n=================\n\nDjango supported versions are now 1.4 (LTS) and 1.6+\n\n* Add ``COUNTRIES_ONLY`` setting to restrict to a specific list of countries.\n\n* Optimize country name translations to avoid exessive translation calls that\n  were causing a notable performance impact.\n\n* PyUCA integration, allowing for more accurate sorting across all locales.\n  Also, a better sorting method when PyUCA isn't installed.\n\n* Better tests (now at 100% test coverage).\n\n* Add a ``COUNTRIES_FLAG_URL`` setting to allow custom flag urls.\n\n* Support both IOC and numeric country codes, allowing more flexible lookup of\n  countries and specific code types.\n\n* Field descriptor now returns ``None`` if no country matches (*reverted in\n  v3.0.1*)\n\n3.0.1 (27 Oct 2014)\n-------------------\n\n* Revert descriptor to always return a Country object.\n\n* Fix the ``CountryField`` widget choices appearing empty due to a translation\n  change in v3.0.\n\n3.0.2 (29 Dec 2014)\n-------------------\n\n* Fix ``CountrySelectWidget`` failing when used with a model form that is\n  passed a model instance.\n\n\n2.1 (24 Mar 2014)\n=================\n\n* Add IOC (3 letter) country codes.\n\n* Fix bug when loading fixtures.\n\n2.1.1 (28 Mar 2014)\n-------------------\n\n* Fix issue with translations getting evaluated early.\n\n2.1.2 (28 Mar 2014)\n-------------------\n\n* Fix Python 3 compatibility.\n\n\n\n2.0 (18 Feb 2014)\n=================\n\nThis is the first entry to the change log. The previous was 1.5,\nreleased 19 Nov 2012.\n\n* Optimized flag images, adding flags missing from original source.\n\n* Better storage of settings and country list.\n\n* New country list format for fields.\n\n* Better tests.\n\n* Changed ``COUNTRIES_FLAG_STATIC`` setting to ``COUNTRIES_FLAG_URL``.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Provides a country field for Django models.",
    "version": "7.6",
    "project_urls": {
        "Change Log": "https://github.com/SmileyChris/django-countries/blob/main/CHANGES.rst",
        "Homepage": "https://github.com/SmileyChris/django-countries/",
        "Source Code": "https://github.com/SmileyChris/django-countries"
    },
    "split_keywords": [
        "django",
        "countries",
        "flags"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27640895f78a93c274328303fdf76096dbf8345ae52cba84fa6a7788dad3d1ce",
                "md5": "4da8751d63947a4f1c33aac5fcf8257f",
                "sha256": "d0a351a88e6bd39bff49b04e54cb8b99aef89ee9ee5893186f9a4326963aa65c"
            },
            "downloads": -1,
            "filename": "django_countryfield-7.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4da8751d63947a4f1c33aac5fcf8257f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 843694,
            "upload_time": "2024-02-12T11:38:38",
            "upload_time_iso_8601": "2024-02-12T11:38:38.486610Z",
            "url": "https://files.pythonhosted.org/packages/27/64/0895f78a93c274328303fdf76096dbf8345ae52cba84fa6a7788dad3d1ce/django_countryfield-7.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbc22ab109183ef724de43faf3693d91b3edeefff1ddac59c78b51cbad52cc3b",
                "md5": "04e44237aa1cef09cd0d091813f77d8d",
                "sha256": "c7c1180e72a9aac019fa2e737153e8c3288b4f189134b5cb37337c43be0da1b7"
            },
            "downloads": -1,
            "filename": "django-countryfield-7.6.tar.gz",
            "has_sig": false,
            "md5_digest": "04e44237aa1cef09cd0d091813f77d8d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 661771,
            "upload_time": "2024-02-12T11:38:42",
            "upload_time_iso_8601": "2024-02-12T11:38:42.154661Z",
            "url": "https://files.pythonhosted.org/packages/cb/c2/2ab109183ef724de43faf3693d91b3edeefff1ddac59c78b51cbad52cc3b/django-countryfield-7.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-12 11:38:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SmileyChris",
    "github_project": "django-countries",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-countryfield"
}
        
Elapsed time: 0.19039s