Package: drf-model-pusher
DRF Model PusherEasy to use class mixins forDjango Rest FrameworkandPusherto keep your API realtime.InstallationDownload from PyPI:pip install drf_model_pusherConfigurationSettings ConfigIn your settings set your Pusher App Id and credentials, the cluster is optionalPUSHER_APP_ID=""PUSHER_KEY=""PUSHER_SECRET=""PUSHER_CLUSTER=""Update Installed AppsAdd drf_model_pusher to yourINSTALLED_APPS:INSTALLED_APPS=["...","drf_model_pusher",]Implement Pusher BackendsDefine somePusherBackendsfor your models and serializers in apusher_backends.pyfile.  The PusherBackend class just needs to define aserializer_classattribute which inherits fromModelSerializer.# example/pusher_backends.pyfromdjango.db.modelsimportModelfromrest_framework.serializersimportModelSerializerfromdrf_model_pusher.backendsimportPusherBackend,PrivatePusherBackendclassMyModel(Model):passclassMyModelSerializer(ModelSerializer):classMeta:model=MyModelclassMyModelPrivateSerializer(ModelSerializer):classMeta:model=MyModelclassMyModelPusherBackend(PusherBackend):serializer_class=MyModelSerializerclassMyModelPrivatePusherBackend(PrivatePusherBackend):serializer_class=MyModelPrivateSerializerImplement ViewsAdd theModelPusherViewMixinmixin class to your views and define aget_pusher_channelsmethod which should return a list of strings to use as channels.# example/views.pyfromrest_framework.viewsetsimportModelViewSetfromdrf_model_pusher.viewsimportModelPusherViewMixinfromexample.serializersimportMyModelSerializerclassMyModelViewSet(ModelPusherViewMixin,ModelViewSet):serializer_class=MyModelSerializerdefget_pusher_channels(self):return["<channel_id>"]Ignoring the current connectionIf you want to ignore the current connection when sending messages you should set ax-pusher-socket-idheader on your requests.  This may be useful if you're modifying resources and receiving the results in a response, you may not want the current connection to listen on these events to prevent duplicating content.The PusherBackend.push_change method accepts anignoreboolean keyword argument which can toggle whether the pusher socket id is used, it defaults toTrue, so including the pusher socket id in the request will ignore the current connection for all pusher events sent by default.SettingsDRF_MODEL_PUSHER_BACKENDS_FILE(default:pusher_backends.py) - The file in your applications to import PusherBackends.DRF_MODEL_PUSHER_DISABLED(default:False) - Determines whether or not to trigger Pusher events.Common IssuesUnregistered BackendsIf you have followed the above steps correctly and your backends are not registering, your app config may not be running it'sreadymethod. To force this, in your apps__init__.pyadd the linedefault_app_config = 'myapp.apps.MyAppConfig'PusherBe aware of any pusher limits and consult their documentation athttps://pusher.com/docsfor some common questions.Pusher has a 10kb default size limit on messages, this can be increased to 256kb by contacting support.ExtendingPusherBackendIf you want to extendPusherBackendorPrivatePusherBackendrather than declaring a new concrete backend, you need to make sure the class is abstract. For example your new base class would be similar to this:classMyPusherBackend(PusherBackend):classMeta:abstract=True# Override whatever methods hereclassMyModelBackend(MyPusherBackend):classMeta:model=MyModelContributionsIt's early days, but if you'd like to report any issues or work on an improvement then please check for any similar existing issues before you report them.