Skip to content

sageteamorg/django-iranian-cities

Django Iranian Cities

The django-iranian-cities is a valuable package based on Django Web Framework for Iranian cities support. You can see full documentation here readthedocs.

SageTeam

License PyPI release Supported Python versions Supported Django versions Documentation Last Commit Languages

Project Detail

  • Language: Python > 3.8
  • Framework: Django > 4.2

Getting Started

  1. Install the package:

    $ pip install django-iranian-cities
  2. Add iranian_cities to INSTALLED_APPS in your Django settings:

    INSTALLED_APPS = [
        ...
        'iranian_cities',
        ...
    ]
  3. Run migrations to apply model changes:

    $ python manage.py migrate
  4. Generate Data: To populate the database with Iranian cities data, use the provided management command. This command will:

    • Check if there is existing data in the tables.
    • Prompt you to confirm if you want to flush the tables if they already contain data.
    • Read CSV files and populate the Province, County, District, City, RuralDistrict, and Village tables with data.
    $ python manage.py generate_city

    If tables contain data, you will be prompted to either flush them or cancel the operation.

Usage

You can use the provided fields and admin mixin in your Django models:

  • Fields:

    from django.db import models
    from iranian_cities.fields import ProvinceField
    
    class TestModel(models.Model):
        province = ProvinceField()

    list of fields:

    • ProvinceField
    • CountyField
    • DistrictField
    • CityField
    • RuralDistrictField
    • VillageField
  • Admin:

    from django.contrib import admin
    from iranian_cities.admin import IranianCitiesAdmin
    from test_app.models import TestModel
    
    @admin.register(TestModel)
    class TestModelAdmin(IranianCitiesAdmin):
        pass

Settings

The package uses several settings for configuration. Make sure the following settings are defined in your settings.py file:

IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED = True
IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED = True
IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED = True
IRANIAN_CITIES_ADMIN_INLINE_ENABLED = False

Explanation of settings:

  • IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED: When set to True, users can add new entries to the admin interface. Set to False to disable adding entries.
  • IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED: When set to True, users can delete existing entries in the admin interface. Set to False to disable deleting entries.
  • IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED: When set to True, users can change existing entries in the admin interface. Set to False to disable changes.
  • IRANIAN_CITIES_ADMIN_INLINE_ENABLED: When set to True, inline admin forms are enabled based on the model type. Set to False to disable inline forms.

Admin

Git Rules

S.A.G.E. team Git Rules Policy is available here:

About

No description or website provided.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages