models.py
from django.db import models
class Device(models.Model):
ip_address = models.CharField(max_length=255)
hostname = models.CharField(max_length=255)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
ssh_port = models.IntegerField(default=22)
Device = models.CharField(max_length=255)
VENDOR_CHOICES = (
('mikrotik', 'Mikrotik'),
('cisco', 'Cisco')
)
vendor = models.CharField(max_length=255, choices=VENDOR_CHOICES)
def __str__(self):
return "{}. {}".format(self.hostname, self.ip_address)
views.py
from django.shortcuts import render, HttpResponse
from .models import Device
def home(request):
all_device = Device.objects.all()
cisco_device = Device.objects.filter(vendor="cisco")
mikrotik_device = Device.objects.filter(vendor="mikrotik")
context = {
'all_device': len(all_device),
'cisco_device': len(cisco_device),
'mikrotik_device': len(mikrotik_device)
}
return render(request, 'home.html', context)
错误:
“设备”类没有“对象”成员pylint(无成员)