Displaying the history of the child object in the history of the parent object in Django admin

Viewed 24

I have a problem in showing a child object in parent history in django admin , as you can see in following screenshot when I create or make a change in child object(comment) from inlines it doesn't display in parent object(ticket) history .

enter image description here

This mode is only for the mode where I use inlines, if I create an object separately through the child model itself, it will not even be displayed as an empty space. I would be very grateful if somebody can tell me how I can display child history in parent history, for example I want to display what happened to child (comment) in blank spaces.

here is my code in admin:

@admin.register(models.Ticket)
class TicketAdmin(SimpleHistoryAdmin):
    actions = ['change_status_to_close']
    autocomplete_fields = ['member']
    list_display =  
    ['id','owner','title','create_time','last_update','status','comments_count','history']
    list_select_related = ['member']
    list_editable = ['status']
    list_filter = ['status',('create_time',DateTimeRangeFilter), 
    ('last_update',DateTimeRangeFilter)]
    list_per_page = 20
    history_list_display = ['changed_fields_with_values','status']
    search_fields = ['id']
    sortable_by = ['create_time','last_update','id','status']



def changed_fields_with_values(self, obj):
    fields = ""
    if obj.prev_record:
        delta = obj.diff_against(obj.prev_record)
        for change in delta.changes:
            fields += str("{} changed from {} to {}".format(change.field, change.old, 
        change.new))
        return fields
    return None



@admin.display()
def history(self,ticket:models.Ticket):
    url = reverse('admin:ticketing_ticket_history',args=[str(ticket.id)])
    return format_html('<a href="{}">History</a>', url)
0 Answers
Related