def check_actionable_model(model): """ If the model is not defined in the ``MODELS`` setting this check raises the ``ModelNotActionable`` exception """ from actstream.settings import MODELS model = model if hasattr(model, 'objects') else model.__class__ if not model in MODELS.values(): raise ModelNotActionable(model)
def check_actionable_model(model): """ If the model is not defined in the ``MODELS`` setting this check raises the ``ModelNotActionable`` exception """ from actstream.settings import MODELS model = model if hasattr(model, 'objects') else model.__class__ if not model in MODELS.values(): raise ModelNotActionable(model)
(self.action_object_content_type.pk, self.action_object_object_id)) def timesince(self, now=None): """ Shortcut for the ``django.utils.timesince.timesince`` function of the current timestamp """ from django.utils.timesince import timesince as timesince_ return timesince_(self.timestamp, now) @models.permalink def get_absolute_url(self): return ('actstream.views.detail', [self.pk]) # convenient accessors actor_stream = Action.objects.actor action_object_stream = Action.objects.action_object target_stream = Action.objects.target user_stream = Action.objects.user model_stream = Action.objects.model_actions # setup GenericRelations for actionable models for model in MODELS.values(): opts = model._meta for field in ('actor', 'target', 'action_object'): generic.GenericRelation(Action, content_type_field='%s_content_type' % field, object_id_field='%s_object_id' % field, related_name='actions_with_%s_%s_as_%s' % ( model._meta.app_label, model._meta.module_name, field), ).contribute_to_class(model, '%s_actions' % field)