As I understand it, you want to create an administrator account for the object that you are updating using your action. I actually did something similar, just like django. As your custom action, you can add this piece of code.
Change . Call this function after the action completes, or rather, I have to say, after changing the state and saving the object.
def log_it(request, object, change_message):
"""
Log this activity
"""
from django.contrib.admin.models import LogEntry
from django.contrib.contenttypes.models import ContentType
LogEntry.objects.log_action(
user_id = request.user.id,
content_type_id = ContentType.objects.get_for_model(object).pk,
object_id = object.pk,
object_repr = change_message,
change_message = change_message,
action_flag = 4
)
log_it(request, status_obj, "Status %s activated" % status_obj.pk)
You can always get which object you updated by retrieving the LogEntry object
log_entry = LogEntry.objects.filter(action_flag=4)[:1]
log_entry[0].get_admin_url()
Hope this helps.
source
share