def follow(user, obj, send_action=True, actor_only=True): """ Creates a relationship allowing the object's activities to appear in the user's stream. Returns the created ``Follow`` instance. If ``send_action`` is ``True`` (the default) then a ``<user> started following <object>`` action signal is sent. If ``actor_only`` is ``True`` (the default) then only actions where the object is the actor will appear in the user's activity stream. Set to ``False`` to also include actions where this object is the action_object or the target. Example:: follow(request.user, group, actor_only=False) """ from actstream.models import Follow, action, update check_actionable_model(obj) follow, created = Follow.objects.get_or_create(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj), actor_only=actor_only) if send_action and created: action.send(user, verb=_('started following'), target=obj) update.send(user) return follow
def unfollow(user, obj, send_action=False): """ Removes a "follow" relationship. Set ``send_action`` to ``True`` (``False is default) to also send a ``<user> stopped following <object>`` action signal. Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(obj) Follow.objects.filter(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj)).delete() update.send(user) if send_action: action.send(user, verb=_('stopped following'), target=obj)