An app that lets you create and find nearby events! When you have something fun to do, invite others. If you are looking forward to meet new people and explore, look for nearby events! Please checkout our mobile app!
This repo is a Django REST framework backend service that provides the APIs that the app uses.
Find nearby events:
GET /apis/events/nearby/?lng=151.195697& lat=-33.870481& dist=0.5 HTTP/1.1
Get event details:
GET /apis/events/1/ HTTP/1.1
As are prerequisite, you should already have Python 3 and pip installed. To start the server, you need to install:
Create the virtual environment and activate it:
python3 -m venv venv
source venv/bin/activate
Use pip to install the requirements
pip3 install -r requirements.txt
Follow this page and this page for more info.
Run the following command to install the required libraries for GeoDjango
sudo apt-get install binutils libproj-dev gdal-bin
Let's use PostgreSQL + PostGIS for our GIS database. You can simply run it as a Docker container:
docker run --name=postgis -d -e POSTGRES_USER=user001 -e POSTGRES_PASS=testpassword -e POSTGRES_DBNAME=ep_gis_db -p 5432:5432 kartoza/postgis:9.6-2.4
Or, if PostgreSQL is already installed on the computer, you can install PostGIS extension.
Refer to this Django document for more detail.
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.measure import D
from apis.models import Event
my_location = GEOSGeometry('POINT(151.195697 -33.870481)', srid=4326)
qs = Event.objects.filter(location__distance_lte=(my_location, D(km=1)))
qs[0].place
Output:
'ChIJkeO_AzquEmsRUpGQn1ZK7Tg'
You will need to get an API key for the server to use the Google Places API.
Export the key as an environment variable:
export PLACES_API_KEY=<Your API Key Here>
Example usage (suppose you already have PLACES_API_KEY
environment variable set up):
from django.contrib.auth.models import User
from apis.models import Event
user = User.objects.get(pk=1)
Event.objects.all()
Output:
<QuerySet [<Event: Google Australia>, <Event: Harbour Bar & Kitchen>, <Event: Google Australia>]>
Now we can create a new event by calling Event.objects.create_event()
:
Event.objects.create_event(host=user, place_id='ChIJN1t_tDeuEmsRUsoyG83frY4')
Event.objects.all()
Output:
<QuerySet [<Event: Google Australia>, <Event: Harbour Bar & Kitchen>, <Event: Google Australia>, <Event: Google Australia>]>