Comments (2)
I think this is asking for something I had a question about as well.
For example, if we have the following Model
s:
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 Article
s changed/updated/deleted for Reporter
X"?
from djangochannelsrestframework.
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)
- exception handling
- Broadcast view_as_consumer
- Got an import error HOT 1
- [BUG] TypeError: has_permission() got an unexpected keyword argument 'scope' HOT 4
- [BUG] HOT 1
- Add @observer_ After model, the database route fails and cannot be written HOT 3
- need more documents for groups_for_signal and groups_for_consumer, and what "__" means in the examples HOT 2
- [BUG] TypeError: can not serialize 'UUID' object models with pk type uuid HOT 2
- Question about client notify HOT 1
- support for request build_absolute_uri
- [BUG] It's impossible to fully use a REAL WORLD viewset via view_as_consumer HOT 1
- [BUG] aws(elastickbeanstalk) and library HOT 1
- [BUG] Can't override get_queryset method when using ObserverModelInstanceMixin and GenericAsyncAPIConsumer HOT 3
- [BUG] app() missing 2 required positional arguments: 'receive' and 'send'
- Document support for channels v4 HOT 1
- [BUG] HOT 1
- Add link to ReadTheDocs in GitHub Project Description HOT 1
- `chat/layout.html` referenced in tutorial is missing HOT 7
- Object level permission HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from djangochannelsrestframework.