Skip to main content

ADSocket transport library with Django integration

Project description

Adsocket transport

Install

pip install adsocket-transport-django

Usage

Using django.db.singals is very easy...

from django.apps import AppConfig
from adsocket_transport_django.apps import ADSocketConfig


class VideosConfig(ADSocketConfig, AppConfig):
    """
    Basic application config
    """
    name = "myapp"
    verbose_name = "My App"

    adsocket_signals = [
        'myapp.ws_message_creator.VideoMessageCreator'

    ]
from adsocket_transport_django.creator import ADSocketCreator
from adsocket_transport_django import CREATE, UPDATE, DELETE, Message

from myapp import models


class VideoMessageCreator(ADSocketCreator):

    class Meta:
        model = models.Todo

    def create(self, model):
        return Message(
            type='publish',
            channel=f'todos:{model.pk}',
            data={'obj': model.pk, 'action': 'create'}
        )

    def update(self, model):
        return Message(
            type='publish',
            channel=f'todos:{model.pk}',
            data={'obj': model.pk, 'action': 'update'}
        )

    def delete(self, model):
        return Message(
            type='publish',
            channel=f'todos:{model.pk}',
            data={'obj': model.pk, 'action': 'delete'}
        )

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

adsocket-transport-django-0.1.3.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

adsocket_transport_django-0.1.3-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

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