如何在Django管理页面模型中添加按钮/单击动作

时间:2018-09-25 01:27:30

标签: python django django-models

我有一个模型,其中有服务器列表...
这是我的模型:

class Ipaddress(models.Model):
    ip_address=models.CharField("Ip address",max_length=20)
    device_type= models.ForeignKey("DeviceType", on_delete=models.CASCADE)
    slug = models.SlugField(unique=True)
    machine_name=models.CharField("Machine Name",max_length=500)
    user=models.CharField("User",max_length=200)
    department= models.ForeignKey("Department", on_delete=models.CASCADE)
    location= models.ForeignKey("Location", on_delete=models.CASCADE)
    updated = models.DateField("Date Updated",null=True)
    note =models.TextField()
    class Meta:
       verbose_name = 'IP Management'

    def __str__(self):
        return self.ip_address[:50]

我想为每个模型记录添加ping服务器操作,如果它恢复了任何响应,则存储“是”。这是管理页面:

from django.contrib import admin
from pages.models import Ipaddress, DeviceGroup, Location,Department, 
from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter


class DepartmentAdmin(admin.ModelAdmin):
    search_fields = ['name']

class LocationAdmin(admin.ModelAdmin):
    search_fields = ['description']   
    list_display =('description',)

class IpaddressAdmin(admin.ModelAdmin):
        prepopulated_fields = {'slug': ('ip_address',)}
        search_fields = ('ip_address',  'machine_name')  

        list_display = ('ip_address', 'device_type', 'machine_name', 'user', 'department','location','updated',)        
        list_display_links =('ip_address', 'device_type', 'machine_name', 'user', 'department','location','updated',)        

        autocomplete_fields = ['location','department',]

        list_filter = (
        ('user', DropdownFilter),
        ('department', RelatedDropdownFilter),
        ('location', RelatedDropdownFilter),
        ('device_type', RelatedDropdownFilter),

    )

我正在考虑添加一个按钮,以弹出一个小对话框,用户将在其中确认ping。需要一些帮助我该怎么做?

0 个答案:

没有答案