{"id":20234800,"url":"https://github.com/datamade/django-geomultiplechoice","last_synced_at":"2025-06-26T19:33:08.531Z","repository":{"id":53047887,"uuid":"233652381","full_name":"datamade/django-geomultiplechoice","owner":"datamade","description":"🗺 A Django widget to select multiple geographic areas","archived":false,"fork":false,"pushed_at":"2023-04-29T01:26:49.000Z","size":3405,"stargazers_count":6,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T19:11:40.570Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datamade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-13T17:24:33.000Z","updated_at":"2024-12-26T06:18:28.000Z","dependencies_parsed_at":"2025-04-10T18:51:35.813Z","dependency_job_id":"9e026f2b-1896-48c8-9e8d-78c98c3876c1","html_url":"https://github.com/datamade/django-geomultiplechoice","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/datamade/django-geomultiplechoice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datamade%2Fdjango-geomultiplechoice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datamade%2Fdjango-geomultiplechoice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datamade%2Fdjango-geomultiplechoice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datamade%2Fdjango-geomultiplechoice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datamade","download_url":"https://codeload.github.com/datamade/django-geomultiplechoice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datamade%2Fdjango-geomultiplechoice/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262132658,"owners_count":23264039,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T08:13:02.400Z","updated_at":"2025-06-26T19:33:08.463Z","avatar_url":"https://github.com/datamade.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗺 GeoMultipleChoice\n\nA Django widget to select multiple geographic areas.\n\n![GeoMultipleChoice demo](https://raw.githubusercontent.com/datamade/django-geomultiplechoice/master/images/just-spaces.gif)\n\nOriginally created by [@jeancochrane](https://github.com/jeancochrane). Packaged up by [@beamalsky](https://github.com/beamalsky).\n\n## Quick Start\n\nThis package is available for installation via PyPI. Simply run:\n\n```bash\npip install django-geomultiplechoice\n```\n\nAdd it to `INSTALL_APPS` in your projects `settings.py` file:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'django_geomultiplechoice',\n    ...\n]\n```\n\nYou should now be ready to start widget setup following the documentation below.\n\n\n## Widget options\n\nThe `example` project in this repo contains the following sample form implementation:\n\n```python\nclass ExampleGeoMultipleChoiceForm(forms.ModelForm):\n    class Meta:\n        model = SelectedArea\n        fields = '__all__'\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        settings_overrides = {\n            'DEFAULT_ZOOM': 12,\n            'DEFAULT_CENTER': (41.88, -87.7),\n            'RESET_VIEW' : True, # Defaults to True\n            # Sets the bounds of RESET VIEW; y min, x min, y max, x max\n            # See https://github.com/makinacorpus/django-leaflet/issues/192\n            'SPATIAL_EXTENT': (-87.3, 41.5, -88, 42.15),\n            'MAP_ID': 'my-example-map', # Defaults to 'map'\n            'MAP_HEIGHT': '400px',\n            'MAP_WIDTH': '100%',\n            'MAP_LAYER_STYLE': {\n              'color': '#7a7a7a',\n              'weight': 3,\n              'opacity': 0.5,\n              'fillColor': '#999999',\n              'fillOpacity': 0.3,\n            },\n            'MAP_LAYER_SELECTED_STYLE': {\n              'color': '#7a7a7a',\n              'weight': 3,\n              'opacity': 0.5,\n              'fillColor': 'black',\n              'fillOpacity': 0.7\n            }\n        }\n\n        self.fields['areas'].widget = GeoMultipleChoiceWidget(\n            choices=[\n                (choice.id, choice) for choice\n                in Area.objects.all()\n            ],\n            settings_overrides=settings_overrides\n        )\n```\n\n`settings_overrides` accepts all arguments used by `django-leaflet` in its [LEAFLET_CONFIG](https://django-leaflet.readthedocs.io/en/latest/templates.html#configuration), in addition to the following:\n\n- `DEFAULT_ZOOM` and `DEFAULT_CENTER` are required.\n- `MAP_ID` sets the html `id` for your widget map. Useful if you have multiple maps on the page.\n- `MAP_HEIGHT` and `MAP_WIDTH` allow you to size the widget in your form. Must be used together.\n- This example uses the default values for `MAP_LAYER_STYLE` and `MAP_LAYER_STYLING`.\n\n`SelectedArea` is a model defined in `example/models.py`, and can be adjusted for your needs.\n\n## Importing Census data\n\nThis repo includes an `example` application using geographical data for 2018 Census block groups in Chicago. Look at `data/Makefile` and `management/commands/import_data.py` to see the ETL pipeline for that data.\n\nIf you'd like to use the same pipeline in your project but for a different area:\n\n1. Copy the `data` directory into your project\n2. Update `STATES` in `scripts/states.py`. If the area is in a new state, create a new entry in STATES for that state; otherwise, update the existing state.\n3. Update `all` in `data/Makefile` to match the form `$(DATA_DIR)/final/cb_2018_{state id}_bg_500k.shp` for each state you're importing shapefiles for.\n4. To delete and regenerate the shapefiles, run:\n\n```bash\ncd data \u0026\u0026 make clean \u0026\u0026 make\n```\n\nOr if your app is containerized:\n\n```bash\ndocker-compose run --rm app make clean -f example/data/Makefile\ndocker-compose run --rm app make -f example/data/Makefile\n```\n\n5. Run `python manage.py import_data` to import the new geographical data. Or if your app is containerized, run `docker-compose run --rm app python manage.py import_data`\n\n## Changing the data structure\n\nThough the example implementation of this widget uses Census block groups, we've intentionally left the door open to varied geographic data. By default the widget expects each area to have the attributes in `example.models.Area`:\n\n```python\nclass Area(models.Model):\n    id = models.CharField(max_length=12, primary_key=True)\n    geom = geo_models.MultiPolygonField(srid=4269)\n```\n\nIf that structure doesn't work for you, it can be changed through creating a new widget that inherits from `django_geomultiplechoice.widgets.GeoMultipleChoiceWidget` and modifying `get_features()`.\n\n## Local development\n\nThis app requires [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) for local development.\n\nTo install and get started, run the following commands in your shell:\n\n```\n# Clone the repo\ngit clone git@github.com:datamade/django-geomultiplechoice.git\n\n# Move into the folder\ncd django-geomultiplechoice\n```\n\nThen build and run the app with Docker:\n\n```bash\ndocker-compose up --build\n```\n\nYou'll also need to import the Census data into your database, for which we've provided a sample `import_data.py`. Open a new window in your terminal and run:\n\n```bash\ndocker-compose run --rm app python manage.py import_data\n```\n\nVisit http://localhost:8000/ and you should see the `example` form running!\n\n![GeoMultipleChoiceWidget example](https://raw.githubusercontent.com/datamade/django-geomultiplechoice/master/images/geomultiplechoicewidget.png)\n\n## Cleaning up\n\nTo remove data files, run:\n\n```bash\ndocker-compose run --rm app make clean -f example/data/Makefile\n```\n\nTo regenerate the Census shapefiles, run:\n\n```bash\ndocker-compose run --rm app make -f example/data/Makefile\n```\n\nTo tear down the app and its volumes, run:\n\n```bash\ndocker-compose down --volumes\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatamade%2Fdjango-geomultiplechoice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatamade%2Fdjango-geomultiplechoice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatamade%2Fdjango-geomultiplechoice/lists"}