Using Snorky with Django

Snorky comes with a Django connector which can prove useful if you develop the server side of your application using Django.

Subscribable models

Adding the snorky.backend.django.subscribable() decorator to a model class will automatically take care of sending notifications to Snorky with each change.

You only need to provide a jsonify() method in the model which returns the representation of the model in a format which can be transformed into JSON.


from django.db import models
from snorky.backend.django import subscribable

class Task(models.Model):
    title = models.CharField(max_length=100)
    completed = models.BooleanField(default=False)

    def jsonify(self):
        return {
            "title": self.title,
            "completed": self.completed,

Subscribable REST views

If you use Django REST Framework for offering a REST API, you can also use the ListSubscribeModelMixin which extends ListModelMixin to provide Snorky subscription support.

class snorky.backend.django.rest_framework.ListSubscribeModelMixin

Provides a list() method which understands the X-Snorky header.


Returns a list of dictionaries of dealer and queries which will be sent to Snorky to authorize a subscription.

By default it returns a list of only one item, with get_dealer() as dealer and get_dealer_query() as query.


Returns the dealer this model is associated with.

By default it returns the value of the property dealer, if any.


Returns the query which will be sent to the dealer.

By default it returns the value of the property dealer_query.


The dealer name to whom subscription will be bound, if get_dealer() is not redefined.


The query which will be sent to the dealer, if get_dealer_query() is not redefined.


from rest_framework import viewsets
import snorky.backend.django.rest_framework as snorky

class TaskViewSet(snorky.ListSubscribeModelMixin,
    model = models.Task
    dealer = "AllTasks"
    dealer_query = None