Record events

You can plug mqueue into your app by creating a mevent whenever you need. It can be in the save method of a model, a form_valid method of a view or in a signal for example.

Event creation

from mqueue.models import MEvent
from myapp.models import MyModel

# simpliest event
MEvent.objects.create(name = 'Something happened!')

# full event
   name = obj.title,
   model = MyModel,
   instance = obj,
   user = request.user,
   url ='/anything/'+obj.slug+'/',
   admin_url ='/admin/app/model/'+str('/',
   notes = 'Object X was saved!',
   event_class = 'Info',
   request = request,
   bucket = "bucket_name",
   data = {"foo": "bar"}

The only required field is name

The instance parameter will not be recorded: it is only used for auto guessing some fields.

Note this method will return the mevent instance just created. There is an option for not to save it immediately:

from mqueue.models import MEvent
from myapp.models import MyModel

# initiate event
mevent = MEvent.objects.create(name='No commit', commit=False)
# do things ...
# update event
mevent.notes='Some stuff'
# and save it

Fields autoguess

If you provided an instance or a content_type and a model mqueue will guess the following fields unless you provided arguments for:

  • user: checks if you model has a user field or an editor field and populates from it
  • url: checks for a get_event_object_url() method in your model, and then check for a get_absolute_url() method and populates from it. Write your own get_event_object_url() method in your model to manage which url will be associated to the object.
  • admin_url: will be reversed from the instance


from mqueue.models import MEvent

MEvent.objects.create(name = 'Something happened!', instance=my_obj)

So that user, url and admin_url will be auto guessed