Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instance-based events #7

Closed
fcurella opened this issue Jun 2, 2016 · 3 comments
Closed

instance-based events #7

fcurella opened this issue Jun 2, 2016 · 3 comments

Comments

@fcurella
Copy link
Contributor

fcurella commented Jun 2, 2016

It would be useful if subscribers could receive events only related to a specific instance.

Scenario:

A web application lets users create their own AddressBook. Each AddressBook have many Contacts:

class AddressBook(models.Model):
    user = models.ForeignKey('auth.User')

@webhook_model(
    on_create=ModelEvent('contact.created'),
)
class Contact(models.Model):
    name = models.CharField(max_length=255)
    address_book = models.ForeignKey(AddressBook, related_name='contacts')

There doesn't seem to be a way for a subscriber to receive contact.created events only for Contacts of a specific AddressBook.

@fcurella
Copy link
Contributor Author

fcurella commented Jun 2, 2016

just found about sender_field. Closing.

@fcurella fcurella closed this as completed Jun 2, 2016
@ask
Copy link
Contributor

ask commented Jun 3, 2016

Yeah, the sender_field should work here when you are mapping to a user, possible that it even works for objects that are not users also.

In my first webhook library written a long time ago, the subscribers could match arbitrary fields on the model: https://github.com/ask/durian
This makes for some pretty expensive queries, but maybe it could be extended in Thorn also.

Maybe the event name could have formats so that (if AddressBook here had a name, and a user can have multiple address books (Work, Friends):

@webhook_model(
    on_create=ModelEvent('contact.created.{.address_book.name}'),
    sender_field="address_book.user",
)

Then you could subscribe to contact.created.*, contact.created.Friends, etc.

@fcurella
Copy link
Contributor Author

fcurella commented Jun 3, 2016

@ask, I've wrote an initial implementation for instance-based event name formatting in #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants