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

Provide a better way to push model changes outside of views #29

Open
aljp opened this issue Sep 9, 2018 · 1 comment
Open

Provide a better way to push model changes outside of views #29

aljp opened this issue Sep 9, 2018 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@aljp
Copy link
Owner

aljp commented Sep 9, 2018

At the moment there's no convenient way to push model changes outside of views. We can do this with something like:

pusher_backends = get_models_pusher_backends(model)
for pusher_backend in pusher_backends:
    pusher_backend(view=self).push_change(...)  # may need to mock view if we're using this outside of the view

However there must be a better way...

@mattjegan mattjegan added the enhancement New feature or request label Sep 9, 2018
@mattjegan
Copy link
Collaborator

Apart from the solution you mention, I have come up with 2 other APIs that might be nicer for our users. The first uses a util function that essentially wraps your solution:

from drf_model_pusher.utils import push_from_model

push_from_model(model)

The second would be to provide a model mixin which implements a push_changes(self, event_name) method that could be called whenever or even overriden:

from drf_model_pusher.mixins import DrfModelPusherModelMixin

class MyModel(models.Model, DrfModelPusherModelMixin):
    ...

@mattjegan mattjegan added this to the 1.0.0 milestone Sep 9, 2018
@mattjegan mattjegan mentioned this issue Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants