54 lines
1.3 KiB
Markdown
54 lines
1.3 KiB
Markdown
# LaTiendaCOOP backend
|
|
|
|
This README aims to document functionality of backend as well as required steps to get it up and running.
|
|
|
|
## Table of Contents
|
|
|
|
- [First Steps](#first-steps)
|
|
- [Location Data](#location-data)
|
|
|
|
## First Steps
|
|
|
|
- Clone repository:
|
|
`git clone git@bitbucket.org:enreda/back-latienda.git`
|
|
- Create file `.env` from `example.env` and populate fields correctly
|
|
|
|
From inside the project's folder:
|
|
- Make migrations:
|
|
```
|
|
python manage.py makemigrations core companies products history stats
|
|
python migrate
|
|
```
|
|
- Start server in development mode: `python manage.py runserver`
|
|
|
|
|
|
## Location data
|
|
|
|
To load initial location data use: `python manage.py addgeo`
|
|
|
|
```python
|
|
from geo.models import Region
|
|
from django.contrib.gis.geos import GEOSGeometry, MultiPolygon
|
|
import json
|
|
|
|
path='gadm36_ESP_1.json'
|
|
|
|
feature_collection = json.loads(open(path).read())
|
|
for feature in feature_collection['features']:
|
|
geom = GEOSGeometry(str(feature['geometry']))
|
|
if feature['geometry']['type'] == "MultiPolygon":
|
|
poly_list = []
|
|
for poly in geom:
|
|
poly_list.append(poly)
|
|
print(poly_list)
|
|
else:
|
|
poly_list = geom
|
|
|
|
geom_geos = MultiPolygon(poly_list)
|
|
|
|
name = feature['properties']['NAME_1']
|
|
region = Region.objects.create(name=name,geo=geom_geos)
|
|
region.save()
|
|
|
|
```
|