5579

Django push notifications with device custom model

Question:

I have a question about Django push notifications.

In my Django project I have my model for mobile device. In this model I have all device info like token (used to send a push notification), device platform (iOS or Android) and other device info.

Now I have implement the logic for sending of these push notifications and I would to use some library like <a href="https://github.com/jleclanche/django-push-notifications" rel="nofollow">django-push-notifications</a>.

I have read the documentation and I realized that this library already uses internally a model with respect to devices: GCMDevice or APNSDevice.

How can I use django-push-notification with my device model? Is there a neat way to do this?

Answer1:

Having done all that work, you probably don't need a library, you can send your GCM messages by making simple HTTP posts to the GCM server it's only a few lines of code. If you are using the <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">python requests library</a> already for http stuff, it's practically a one liner.

requests.post( 'https://gcm-http.googleapis.com/gcm/send', data = json.dumps(message), headers = {'Authorization': auth_token,'Content-Type': 'application/json'})

Where message is your GCM message which follows the guidelines on <a href="https://developers.google.com/cloud-messaging/http" rel="nofollow">GCM docs</a> and looks like this.

{ "notification": { "title": "Portugal vs. Denmark", "text": "5 to 1" }, "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..." }

auth_token will look like 'key=YOUR_GCM_KEY'

Lastly if you are really keen to use a more complex library but want to preserve your models, consider <a href="https://github.com/geeknam/python-gcm" rel="nofollow">Python GCM</a> which can be plugged into django quite easily.

Recommend

  • Javascript cookie expiration/deletion on different browsing scenarios
  • Can't start sql server in single user mode
  • Custom Membership/Role/Profile Providers WITHOUT inheriting the MembershipProvider, RoleProvider, et
  • Set default application configs for Elixir packages
  • obtain command line arguments in unit test
  • How to extract a list of elements given by their indices from a numpy array efficiently?
  • Where to implement INotifyPropertyChanged interface in software architecture?
  • How can I increment one line at a time from a text file and sed the output to another file?
  • Stream data into rotating log tables in BigQuery
  • JSON conversion in javascript
  • How to call native VC++6 library (with std::string as parameters) from C#
  • Combining two double[] arrays into double[,]
  • Javascript to Excel: bad performance for lack of “range” method
  • Using C# LINQ Expressions for both Value Types and Reference Types
  • GetAltTabInfo usage?
  • Centering an item in the dead center of a page
  • How to port C# Console application to Windows Phone
  • Working with big files in classic ASP
  • Django how to modify database records by template
  • When is locking on types a good idea?
  • How to discover a file is changed in GIT during a push
  • C: Custom strlen() library function
  • How to format data from string variable
  • Is it safe to accept URL parameters for populating the `url_for` method?
  • Why does Sencha 2 only work in Webkit browsers?
  • Why is django manage.py syncdb failing to create new columns on my development server?
  • How to add closing tag for canvas in three js rendered Canvas?
  • how to change api_token column in token guard
  • Django return user model id with L
  • Does Apportable support to build library binary (.a/.so)?
  • UWP/C# - Issue with AQS and USB Devices
  • Moving Android View and preventing onDraw to be called over and over again
  • Django simple Captcha “No module named fields” error
  • Atlas images wrong size on iPad iOS 9
  • Projection media query: browser support and workarounds?
  • WOWZA + RTMP + HTML5 Playback?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • LevelDB C iterator
  • Can't mass-assign protected attributes when import data from csv file