Add Project Files
This commit is contained in:
27
hosts/admin.py
Normal file
27
hosts/admin.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import requests
|
||||
from django.contrib import admin
|
||||
from .models import Host
|
||||
|
||||
|
||||
def toggle_check_hosts(queryset):
|
||||
for item in queryset:
|
||||
try:
|
||||
r = requests.get(item.host_name)
|
||||
if r.status_code == 200:
|
||||
item.status = True
|
||||
else:
|
||||
item.status = False
|
||||
except requests.RequestException:
|
||||
item.status = False
|
||||
item.save()
|
||||
|
||||
|
||||
toggle_check_hosts.short_description = "Проверить"
|
||||
|
||||
|
||||
@admin.register(Host)
|
||||
class HostAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"host_name", "port", "status", "status_code", "created", "updated"
|
||||
)
|
||||
actions = [toggle_check_hosts]
|
||||
Reference in New Issue
Block a user