Giter Site home page Giter Site logo

Comments (2)

johnthagen avatar johnthagen commented on June 12, 2024

I think this is asking for something I had a question about as well.

For example, if we have the following Models:

from django.db import models


class Reporter(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.EmailField()


class Article(models.Model):
    headline = models.CharField(max_length=100)
    pub_date = models.DateField()
    reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)

Can an Observer listen for "all Articles changed/updated/deleted for Reporter X"?

from djangochannelsrestframework.

hishnash avatar hishnash commented on June 12, 2024

Yes you will need to create a custom observer for this.

In this blog post there is a custom subscription for a hashtag.

If you created a ArticleConsumer and defined a @model_observer method with @{..}.groups_for_signal and @{...}.groups_for_consumer that group the articles by reported id and let users subscribe based on reporter id respectively.

you will also need to create a custom subscribe_to_reporter action that captures the id of the reporter you want to subscribe to and calls the subscribe method on the observer.

I know the syntax for this is all rather obscure and hard to figure out. I have attempted a few differnt passes at trying to create a more declarative aporach that would be easier to work with but due to the limitations of how django events work and channels so as to avoid loads of extra db lookups I think what is there right now is the best solution.

from djangochannelsrestframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.