Skip to main content

Django application to send push notifications to IOS and Android devices using Amazon SNS.

Project description

Sloop

This package contains some tools that will ease the implementation of push notifications using AWS SNS and other backends into django projects.

Django-Sloop

Installation

  1. Install the package via Github or PIP (pip install django-sloop)

  2. Add django_sloop to the INSTALLED_APPS list in the settings file.

  3. Extend the django_sloop.models.AbstractSNSDevice class and create your own push token device model.

# models.py

from django_sloop.models import AbstractSNSDevice


class Device(AbstractSNSDevice):
    pass
    
    # (Optional) if you need to override Meta.
    class Meta(AbstractSNSDevice.Meta):
        pass
  1. Make sure that you fill necessary information at the settings file:
# settings.py

DJANGO_SLOOP_SETTINGS = {
    "AWS_REGION_NAME": "",
    "AWS_ACCESS_KEY_ID": "",
    "AWS_SECRET_ACCESS_KEY": "",
    "SNS_IOS_APPLICATION_ARN": "test_ios_arn",
    "SNS_IOS_SANDBOX_ENABLED": False,
    "SNS_ANDROID_APPLICATION_ARN": "test_android_arn",
    "LOG_SENT_MESSAGES": False,  # False by default.
    "DEFAULT_SOUND": "",
    "DEVICE_MODEL": "module_name.Device",
}

You cannot change the DEVICE_MODEL setting during the lifetime of a project (i.e. once you have made and migrated models that depend on it) without serious effort. The model it refers to must be available in the first migration of the app that it lives in.

  1. Create migrations for newly created Device model and migrate.

Note: django_sloop's migrations must run after your Device is created. If you run into a problem while running migrations add following to the your migration file where the Device is created.

run_before = [
   ('django_sloop', '0001_initial'),
]
  1. Add django_sloop.models.PushNotificationMixin to your User model.
class User(PushNotificationMixin, ...):
    pass

user.send_push_notification_async(message="Sample push notification.")
  1. Add django_sloop.admin.SloopAdminMixin to your UserAdmin to enable sending push messages to users from Django admin panel.
# admin.py

from django_sloop.admin import SloopAdminMixin
from django.contrib import admin

class UserAdmin(SloopAdminMixin, admin.ModelAdmin):
    
    actions = ("send_push_notification", )
    
  1. Add django rest framework urls to create and delete device.
# urls.py
from django.urls import path
from django.urls import include

urlpatterns = [
    # ...
    path('api/devices/', include('django_sloop.urls')),
    # ...
]

Done!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-sloop-1.0.6.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

django_sloop-1.0.6-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file django-sloop-1.0.6.tar.gz.

File metadata

  • Download URL: django-sloop-1.0.6.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for django-sloop-1.0.6.tar.gz
Algorithm Hash digest
SHA256 12871296041f182ad5598e1994c8b82f9aa05a25c6e059cd352aa881d898d557
MD5 c130529c4cfbb48f68cfad1703856311
BLAKE2b-256 40314e5c9ccdd0fdb18c1483fc27fd312814aef25fbc67f9b1660ce91969d9d3

See more details on using hashes here.

File details

Details for the file django_sloop-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_sloop-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 af583d7dbd752456670ebb67f158b50373d3836bf1a59e443cc63beb088f274f
MD5 775522e97d9799940b4e7775691d26e8
BLAKE2b-256 ce337904be19eb32a7feb9d0a73ad357445b50a42fb3c68ffea62fe1915261c5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page