0

I followed this tutorial : https://docs.djangoproject.com/en/2.2/ref/contrib/admin/actions/

And i cant't see log about this action in to History.(But changed,.. default actions of django admin can show blog on there)

How can i add log to History like 'User_1 Make published' ? Thank you so much.

Quang Tu
  • 44
  • 1
  • 6

1 Answers1

2

You can create a simple log entry section in the admin page like so:

admin.py:

from django.contrib import admin


class LogEntryAdmin(admin.ModelAdmin):
    list_display = ('id', 'get_string', 'action_time', 'object_id')
    actions = None

    def get_string(self, obj):
        return str(obj)

    search_fields = ['=user__username', ]
    fieldsets = [
        (None, {'fields':()}), 
        ]

    def __init__(self, *args, **kwargs):
        super(LogEntryAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = None

admin.site.register(admin.models.LogEntry, LogEntryAdmin)

It can show a page of every changes that made on the data form the admin pages form which user

Linh Nguyen
  • 3,452
  • 4
  • 23
  • 67
  • thank you so much. But tried last day and i had a answer for my stuff. I just use something like Post.objects.update(changed_by=request.user) . And add it in def function i created. ^^ it 'll work like a trigger. But thank you your comment <3 – Quang Tu Nov 01 '19 at 16:36
  • Yes that's also a way but it involve changing your model which i don't support because it will affect other functions that use the model – Linh Nguyen Nov 04 '19 at 02:19