You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@RaitoBezarius Can you clarify what you mean with an example?
Channels and listeners behave much like Django signals. A model can be associated to a channel and then a channel can be associated to as many listener functions as we want. From the unit tests for example:
@atomic
@pgpubsub.post_insert_listener(AuthorTriggerChannel)
def create_first_post_for_author(
old: Author, new: Author, context: Optional[Dict[str, Any]] = None
):
print(f'Creating first post for {new.name}')
content = 'Welcome! This is your first post'
if context and 'content' in context:
content = context.get('content')
Post.objects.create(
author_id=new.pk,
content=content,
date=datetime.date.today(),
)
@pgpubsub.post_insert_listener(AuthorTriggerChannel)
def another_author_trigger(
old: Author, new: Author, context: Optional[Dict[str, Any]] = None
):
print(f'Another author trigger')
Using the same channel, it seems like we cannot listen on multiple events, is that on purpose?
I'd have expected to write "one channel" per model, but it feels like we need to write as many channels as we have events need.
Would that make sense to document in the FAQ?
The text was updated successfully, but these errors were encountered: