[Django]-Django-admin action in 1.1

9๐Ÿ‘

As far as i can understand you want make an admin log-entry for the object you update using your custom action. I actually did something like that, purely as django does it. As its your custom action you can add this piece of code.

Edit: Call this function after your action finishes, or rather i should say, after you change the status and save 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, # Message you want to show in admin action list
        change_message  = change_message, # I used same
        action_flag     = 4
    )

# call it after you save your object
log_it(request, status_obj, "Status %s activated" % status_obj.pk) 

You can always get which object you updated by fetching LogEntry object

log_entry = LogEntry.objects.filter(action_flag=4)[:1]
log_entry[0].get_admin_url()

Hope this helps.

๐Ÿ‘คsimplyharsh

0๐Ÿ‘

It is very easy!

Just make a loop of your queryset, then you can access each field of that row and store it where you want.

for e in queryset:          
   if (e.status != "pending"):
       flag = False
๐Ÿ‘คha22109

Leave a comment