简体   繁体   中英

How to add a custom button beside the list display in django admin panel? To edit the form from list display it self

I have attached my admin panel screenshot https://i.stack.imgur.com/wWZ4K.png

Here is my admin.py code:

`from django.contrib import admin
        from .models import *
        from django.utils import *
        import csv
        from django.http import HttpResponse
        

        class ProductAdmin(admin.ModelAdmin):
            search_fields = ('name',)
            list_display = ('name','price',)
        
        admin.site.register(Product,ProductAdmin)`
    

Instead of adding a button, I would suggest making the 'price' field editable. Use the attribute list_editable = ('price',).

class ProductAdmin(admin.ModelAdmin):
    search_fields = ('name',)
    list_display = ('name','price',)

    list_editable = ('price',)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM