This repo acts as a decent starting point for those who are looking for a custom backend deployment for their mobile app. It includes a full-serving django project which exposes a RESTful API, manages user instances and is highly configurable.
In fact, this project is not a package that you can include in your project and use right-away, but it's a project template that you can download, extend and keep working on it as a base for your new project.
3rd-party apps it includes:
django-storages, to store files in AWS S3 (the most commonly used object storage)
django-allauth, for social media authentication
django-anymail[mailgun], to send transactional emails using Mailgun (first 10k messages/month are free)
djangorestframework, for the RESTful API
django-rest-swagger, to automatically generate documentation for your RESTful API endpoints
django-rest-auth, to provide social media authentication over the API
django-filters, which provides filtering capabilities in the DRF API views
django-guardian, for custom object or model level permissions
celery, for background tasks handling. By default, it's expected to be used for device registration on the AWS SNS service.
django-extensions, offering a collection of custom extensions for Django
django-environ, following the 12-factor methodology
- virtualenv (recommended)
How to use
- Clone this repo on your local machine:
git clone https://github.com/intelligems/django-mobile-app
- We strongly advise to create a Python virtual environment and install the project requirements in there:
mkvirtualenv <env-name> --python=`which python3`
- Install project requirements inside your newly created local virtual environment:
pip install -r requirements.txt
- Inside the
settingspath, create an
.envfile. Add in there all the environment variables that should be included in the project runtime.
- It's time to perform your first database migrations - no worries, we have included them too:
python manage.py migrate
- Run the server!
python manage.py runserver 0.0.0.0:80
Registering Push Devices
push_devices app usage, you are expected to use the
AbstractMobileDevice abstract model.
You can extend it and add any fields you wish, but you are not allowed (by Django) to override the same fields that the
AbstractMobileDevice model uses.
In order to create a push device, inside the create view of your devices' API, import the sns registration method
from core.mobile_devices.tasks import register_device_on_sns
and use the
delay method to register the newly created device on SNS. This will assign the ARN endpoint on the device model, so that you will be able to publish push notifications to your registered push device.
device = Device.objects.create(**data) register_device_on_sns.delay(device)