Enhance UPS host display with location and IP address

This commit is contained in:
xiaji
2026-05-18 11:18:21 +08:00
parent 58a49b1cee
commit 1c5a56c3dd

View File

@@ -49,9 +49,12 @@ class UPSHost(models.Model):
return sum(battery.quantity for battery in self.battery_set.all())
def __str__(self):
parts = [f'{self.brand} {self.model}']
if self.location:
parts.append(f'[{self.location}]')
if self.ip_address and not self.ip_address.startswith('-'):
return f'{self.brand} {self.model} - {self.ip_address}'
return f'{self.brand} {self.model}'
parts.append(f'({self.ip_address})')
return ' '.join(parts)
class Meta:
verbose_name = 'UPS主机'