First off: this sounds like a bug, please log an issue on Github with as much info as possible (router, serializer and model etc. if you can)
I would recommend not using `SelfPublishModel` in this scenario, instead publish the event manually.
If you do it manually you lose out on having it publish when you save via admin (but you do get more control over when the publish occur, and you could of course add an action to admin to do this).
Two ways you can publish the model:
Using `publish_data` you could go about it this way
from swampdragon.pubsub_providers.data_publisher import publish_data
def publish_event(event):
serializer = EventSerializer(instance=event)
channel = 'public_events'
publish_data(channel, serializer.serialize())
The "drawback" of this is that you have to know the actual channel you are publishing to, and you wouldn't be able to use the `DataMapper` in JavaScript since it doesn't know if this set of data was a create, delete or an update action (publish_data was made with the intent to publish dictionaries rather than models).
If you use the `DataMapper` in JS, or have lots of subscribers on various channels all relating to the same model, or don't know the channel name, then use `publish_model` instead (this is probably the most recommended way).
`publish_model` will find the channels for you, but requires to know the action (was it an update, was it a delete or was it created?)
from swampdragon.pubsub_providers.model_publisher import publish_model
def publish_event(event):
action = 'created' # you can use created, updated, deleted
publish_model(event, EventSerializer, action)
So if you have a view where you create/update events you can simply add this (assuming CBV) to your view:
class EventCreateView(CreateView):
model = Event
def form_valid(form):
event = form.save()
publish_event(event)
return HttpResponseRedirect(self.get_success_url())
You could easily modify `publish_event` to take the action as a parameter