Skip to main content

Countries for django

Project description

Django Country Kit

Django Country Kit is a Django app that provides country-related functionality, including a custom model field for storing country codes, a form widget for selecting countries, and associated tests.

Features

  • Country Model Field: Easily store and retrieve country codes in your Django models.
  • Country Widget: A form widget for rendering a dropdown list of countries in your Django forms.

Installation

  1. Install Django Country Kit using pip:

    pip install django-country-kit
    
  2. Add 'django_country_kit' to your INSTALLED_APPS in your Django project's settings:

    INSTALLED_APPS = [
        # ...
        'django_country_kit',
        # ...
    ]
    
  3. Run collectstatic:

    python manage.py collectstatic
    

Usage

Country Model Field

In your models, use the CountryField to store country codes:

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

class YourModel(models.Model):
    country = CountryField()

For multiple selections:

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

class YourModel(models.Model):
    countries = CountryField(multiple=True)

Country Widget

In your forms, use the CountryWidget to render a dropdown list of countries:

from django import forms
from django_country_kit.widgets import CountryWidget

class YourForm(forms.Form):
    country = forms.CharField(widget=CountryWidget())

For multiple selections:

from django import forms
from django_country_kit.widgets import MultipleCountryWidget

class YourForm(forms.Form):
    countries = forms.CharField(widget=MultipleCountryWidget())

Country Class

The Country class represents a country and provides properties for accessing its name and alpha3 code. This class is part of the Django Country Kit and offers convenient functionality for handling country-related data.

Usage

You can create an instance of the Country class to retrieve information about a specific country. Here's how you can use it:

from django_country_kit.base import Country

# Create a Country instance with a specific country code
country = Country(code='US')

# Retrieve the name of the country
country_name = country.name  # Returns 'United States'

# Retrieve the alpha3 code of the country
country_alpha3 = country.alpha3  # Returns 'USA'

Custom settings

Django Country Kit provides custom settings for further customization of country data:

  • OVERRIDE_COUNTRIES: Allows users to override specific countries with custom data.
  • EXCLUDE_COUNTRIES: Allows users to exclude specific countries from the available choices.
  • INCLUDE_COUNTRIES: Allows users to include specific countries in the available choices.

You can customize these settings in your Django project's settings file to tailor the country data according to your needs.

We appreciate your feedback and contributions to improving Django Country Kit!

Development

If you want to contribute to Django Country Kit, follow these steps to set up your development environment:

  1. Install pipenv if you haven't already:

    pip install pipenv
    
  2. Clone the repository:

    git clone https://github.com/your_username/django-country-kit.git
    
  3. Navigate to the project directory:

    cd django-country-kit
    
  4. Install development dependencies:,

    pipenv install --dev
    
  5. Activate the virtual environment:

    pipenv shell
    
  6. Run migrations:

    python manage.py migrate
    
  7. Run collectstatic:

    python manage.py collectstatic
    
  8. Start the development server:

    python manage.py runserver
    

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

django-country-kit-0.0.4.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

django_country_kit-0.0.4-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file django-country-kit-0.0.4.tar.gz.

File metadata

  • Download URL: django-country-kit-0.0.4.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for django-country-kit-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3a7e6ec76402c94f4d0c6371747ad50508a6095fa74b886cf78f5e0abf9cf46b
MD5 b5ba636bb9fb5a8bc5b5c71a11ed0b12
BLAKE2b-256 4c76897944c27f7951547dc7a4a5239f2607c22e7829a361f07caa2de6314ed8

See more details on using hashes here.

File details

Details for the file django_country_kit-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_country_kit-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 de8c9d77c7a40f3cedac1d0907a0a50d7ca5e8d268abd840ed08737edc796a18
MD5 0d9095bffd2e082e30357f9b3edc2872
BLAKE2b-256 775dcc8869d54aedd54241338cc5eb71eb9a0fef60531b1ff98e7059a24a32b2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page