Skip to main content

Django Nigerian States is a comprehensive third-party Django application that provides a robust and efficient way to manage and interact with geopolitical data related to Nigeria.

Project description

Django Nigerian States is a comprehensive third-party Django application that provides a robust and efficient way to manage and interact with geopolitical data related to Nigeria. This application is designed to seamlessly integrate with your Django projects, providing pre-defined Django fields for all states, their capitals, local government areas, and geopolitical zones in Nigeria.

Requirements

  • Python 3.10

  • Django 5.0.1

Installation Steps

  1. Install Nigerian States using pip:

    pip install django_nigerian_states
  2. Add ‘nigerian_states’ to INSTALLED_APPS in your Django project’s settings.

  3. Migrate your database:

    python manage.py makemigrations
    python manage.py migrate
  4. Load Fixtures:

    python manage.py loaddata fixtures

Usage

You can integrate Nigerian States into your Django forms seamlessly. Below is an example:

Example Usage

from django import forms
from nigerian_states.fields import StateFormField, LocalGovernmentField

class AboutForm(forms.ModelForm):
    zone = GeoPoliticalZoneField(
        label="Zone",
        help_text="Select a zone from the dropdown",
        widget=forms.Select(attrs={"class": "form-select"}),
    )
    state = StateField(
        label="Name of States",
        help_text="Select a state from the dropdown",
        widget=forms.Select(
            attrs={"class": "form-select", "required": "required"}
        ),
    )
    lga = LocalGovernmentField(
        label="Local Governments",
        help_text="Select a LGA from the dropdown",
        widget=forms.Select(
            attrs={"class": "form-select", "required": "required"}
        ),
    )

Configuration

You can configure Nigerian States by modifying your Django project settings.py:

DEFAULT_GEO_POLITICAL_ZONES = ["North Central", "North West"]

Setting DEFAULT_GEO_POLITICAL_ZONES restricts the choices for (GeoPoliticalZoneField, StateField, or LocalGovernmentField) to the specified zones.

You can also customize fields further by utilizing additional keyword arguments like empty_label and zones:

from django import forms
from nigerian_states.fields import StateFormField, LocalGovernmentField
from nigerian_states.enums import PoliticalZones

zone = GeoPoliticalZoneField(
    label="Zone",
    empty_label="Select a GeoPolitical Zone",  # the first option in the dropdown
    zones=[PoliticalZones.SOUTH_EAST, PoliticalZones.SOUTH_EAST], # limits the field to specified political zones, overriding DEFAULT_GEO_POLITICAL_ZONES
)

Note: In the above, by passing the zones kwargs in the field, It would override the DEFAULT_GEO_POLITICAL_ZONES set in the settings.py

Template Tags

To use the template tags, you need put {% load state_tags %} at the top of your django template. The following template tags are available for use in your Django templates:

  • {% get_states_in_zone ZONE_NAME %}: Retrieves the list of states in a geopolitical zone.

  • {% get_capital STATE_NAME %}: Returns the capital of the state provided

  • {% get_lgas_in_state STATE_NAME %}: Retrieves the list of names of Local Government in the state.

  • {% is_state_in_zone ZONE_NAME STATE_NAME %}: Returns a boolean True if the state is from the GeoPolitical Zone.

  • {% is_lga_in_state STATE_NAME LGA_NAME %}: Returns a boolean True if the lga is from the state. else False

  • {% default_zone %}: Returns the default zone set in the settings.DEFAULT_GEO_POLITICAL_ZONES if set or empty list

  • {% get_zone STATE_NAME %}:Returns the name of the Zone which the state belongs to

  • {% get_zone_info STATE_NAME %}: Returns a dict of information about the state.

Contributing

Contributions are welcomed and appreciated! Follow these steps to contribute:

  1. Fork the repository.

  2. Create a new branch for your feature or bug fix.

  3. Make changes, ensuring to write tests to confirm your changes did not break anything.

  4. Push the changes to your fork.

  5. Submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Developed by Afeez Lawal

Contact Me:

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_nigerian_states-1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

django_nigerian_states-1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file django_nigerian_states-1.0.tar.gz.

File metadata

  • Download URL: django_nigerian_states-1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for django_nigerian_states-1.0.tar.gz
Algorithm Hash digest
SHA256 2fde3c8f35bd2646d50108724d517cd5ad51851073e0fc6159c05b6a8e899c7b
MD5 63c0030b8a1c151c10ce09be2725ff2f
BLAKE2b-256 8e06063648d2ff4d8c5e4f3233d6c921cae36553ad5fea3f1ade97759f876394

See more details on using hashes here.

File details

Details for the file django_nigerian_states-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_nigerian_states-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f32f68689a8d18e994f8936ddfe1dd2f83b198c104bf6634a3b37f217722ce9e
MD5 20be0bd2d664b0e123b2361ce0963eaa
BLAKE2b-256 367cf06396dea6066dd403eaf08be9184c5f85a1bf812469ea8508c395752051

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