Skip to content

Feature/country metadata#487

Open
mymi14s wants to merge 5 commits intoSmileyChris:mainfrom
mymi14s:feature/country-metadata
Open

Feature/country metadata#487
mymi14s wants to merge 5 commits intoSmileyChris:mainfrom
mymi14s:feature/country-metadata

Conversation

@mymi14s
Copy link

@mymi14s mymi14s commented Feb 3, 2026

Rich Country Metadata

Summary

This PR introduces country metadata (currency_name, currency_symbol, calling_code, capital_city, utc_offset, continent, date_format, official_language and timezones) to the Country object and enhances Django Rest Framework serialization to easily expose this data to frontends.

Features

  • Rich Metadata on Country Objects:
    Access essential country details directly:

    • currency_name & currency_symbol (e.g., "British pound", "£")
    • calling_code (e.g., "+44")
    • capital_city (e.g., "London")
    • utc_offset, continent, date_format, official_language, timezones.
  • Optimized:
    Metadata is sourced from a local YAML file and cached in memory.

  • DRF Integration:
    Added the fields to serializers.

Usage

Python / Django Models

from django_countries.fields import Country

nz = Country('NZ')
print(f"{nz.name} uses {nz.currency_name} ({nz.currency_symbol})")
# Output: New Zealand uses New Zealand dollar ($)

# Works directly on model instances too
user.country.calling_code  # e.g., '+64'

# Access rich metadata properties directly
print(f"Capital: {nz.capital_city}")
print(f"Calling Code: {nz.calling_code}")
print(f"Languages: {', '.join(nz.official_language)}")

# Or accessing from a model instance
class Person(models.Model):
    country = CountryField()

person = Person.objects.get(name='Alice')
person.country.currency_name
person.country.currency_symbol
person.country.calling_code
person.country.utc_offset
person.country.capital_city
person.country.continent
person.country.date_format
person.country.official_language
person.country.timezones

Sample Output

Here is the data available for the Country('NZ') object:

Property Value Description
currency_name 'New Zealand dollar' Full name of the currency.
currency_symbol '$' Currency symbol.
calling_code '+64' International dialing code.
utc_offset '-11:00' Primary UTC offset.
capital_city 'Wellington' Capital city name.
continent 'Oceania' Continent the country belongs to.
date_format 'DD/MM/YYYY' Common date format used.
official_language ['English', 'Māori', 'New Zealand Sign Language'] List of official languages.
timezones ['UTC−11:00', 'UTC−10:00', 'UTC+12:00', 'UTC+12:45', 'UTC+13:00'] All timezones observed.

@mymi14s
Copy link
Author

mymi14s commented Feb 3, 2026

@SmileyChris some of the changes to the code style (imports) was due to my use of python black to format the source files.

@mymi14s mymi14s marked this pull request as draft February 3, 2026 19:07
@mymi14s mymi14s marked this pull request as ready for review February 3, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant