如何根據(jù)函數(shù)的結(jié)果修改類的布爾字段的值?我正在嘗試做的是一個函數(shù),它 ping (icmp) 一個位于“Cliente”類中的 ip,并根據(jù)結(jié)果更改類中的值“ping_status”。我是 python 的新手,所以我沒有太多的知識,我一直在嘗試這樣做 1 周,但我做不到。models.pyclass Cliente(models.Model):razon_social = models.CharField('Razon Social', max_length=50)numero_cuenta = models.CharField('Numero de cuenta',max_length=6)nombre_contacto = models.CharField('Nombre del contacto', max_length=50)numero_del_contacto = models.CharField('Numero del contacto', max_length=10)email = models.EmailField('Correo Electronico', blank=True, null=True)tiene_as_propio = models.BooleanField('Tiene ASN priopio', default=False)ipv4 = models.GenericIPAddressField('IP', default='192.168.0.0')segmento = models.CharField('Segmento', max_length=15)asn= models.CharField(max_length=6, blank=True, null=True)created = models.DateTimeField('Creado el', auto_now_add=True ,blank=True, null=True)updated = models.DateTimeField('Actualizado el', auto_now_add=True, blank=True, null=True)topologia = models.FileField('Topologia', blank=True, null=True)ping_status = models.BooleanField('Ping', blank=True, null=True)def Meta(self): verbose_name = 'cliente' verbose_name_plural = 'clientes'def __str__(self): return self.razon_social我的功能如下所示:def do_ping(): """Realice un nuevo ping y guárdelo en la base de datos.""" ip_clientes = Cliente.objects.values_list('ipv4') for ip in ip_clientes: ip = (list(ip)) for ping in ip: ping = subprocess.call(['ping', '-n', '1', '-w', '2',ping], stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'))但在此之后我不知道如何獲取類值并修改它
根據(jù)函數(shù)的結(jié)果更改類中字段的值
慕尼黑5688855
2023-02-22 15:09:28