Closed aktarmiah closed 1 year ago
@aktarmiah That should be supported, you just need to define your listener correctly. For the scenario you mentioned, there's a built in pgpubsub.post_save_listener
which will trigger on both creations and updates. See django-pgpubsub/pgpubsub/tests
/listeners.py which has some examples of channels which trigger on multiple actions
@pgpubsub.post_save_listener(ChildTriggerChannel)
def post_child_save(old: Child, new: Child):
print(f'New child created {new}.')
@aktarmiah Hope that helped :). Let me know, otherwise I will mark the issue as resolved.
While the post_save_listener
does indeed do the job of combining the create and update trigger, I'm still finding that I can't use the same channel elsewhere.
For eg
@post_save_listener(mychannel)
def foo(old, new):
print("foo")
# Results in console error saying the channel is already being used
@post_save_listener(mychannel)
def bar(old, new):
print("bar")
@aktarmiah Ah, that does sound like a bug then. I will look at that for the next release, which I hope will be within the next few weeks.
@aktarmiah I have merged a fix for this in https://github.com/Opus10/django-pgpubsub/commit/66c783d0a80bcf837124744aa7e70e0bb69ac646. I'll do a proper release to pypi alongside fixes for some of the other issues soon.
I'm finding that I have to create multiple trigger based channels relating to the same model or I get an error. For example I'd like to trigger on insert and update for the same model but I need two separate channels for this.
Am I missing something