[Fixed]-List_editable is super slow on save

1👍

✅

I ended up replacing list_editable by an admin action. My theory is that when you use “list_editable”, it parses every single object. So, if you have 1,000,000 items, it will parse every one of them.

Here is my solution:

class ClientASTMAdmin(admin.ModelAdmin):
    actions = ('exclude_keyword', )

    list_display = (
        'id',
        'day',
        'search_term',
        'is_exclude',
    )

    def exclude_keyword(self, request, queryset):
        for instance in queryset:
            instance.is_exclude = not instance.is_exclude
            instance.save()
    exclude_keyword.short_description = 'Exclude (or include) keywords'

It’s faster because it only update the selected items.

Leave a comment