The django-iranian-cities is a valuable package based on Django Web Framework for Iranian cities support. You can see full documentation here readthedocs.
- Language: Python > 3.8
- Framework: Django > 4.2
-
Install the package:
$ pip install django-iranian-cities
-
Add
iranian_cities
to INSTALLED_APPS in your Django settings:INSTALLED_APPS = [ ... 'iranian_cities', ... ]
-
Run migrations to apply model changes:
$ python manage.py migrate
-
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
, andVillage
tables with data.
$ python manage.py generate_city
If tables contain data, you will be prompted to either flush them or cancel the operation.
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
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 toTrue
, users can add new entries to the admin interface. Set toFalse
to disable adding entries.IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED
: When set toTrue
, users can delete existing entries in the admin interface. Set toFalse
to disable deleting entries.IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED
: When set toTrue
, users can change existing entries in the admin interface. Set toFalse
to disable changes.IRANIAN_CITIES_ADMIN_INLINE_ENABLED
: When set toTrue
, inline admin forms are enabled based on the model type. Set toFalse
to disable inline forms.
S.A.G.E. team Git Rules Policy is available here: