Enhance UPS host display with location and IP address
This commit is contained in:
@@ -49,9 +49,12 @@ class UPSHost(models.Model):
|
|||||||
return sum(battery.quantity for battery in self.battery_set.all())
|
return sum(battery.quantity for battery in self.battery_set.all())
|
||||||
|
|
||||||
def __str__(self):
|
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('-'):
|
if self.ip_address and not self.ip_address.startswith('-'):
|
||||||
return f'{self.brand} {self.model} - {self.ip_address}'
|
parts.append(f'({self.ip_address})')
|
||||||
return f'{self.brand} {self.model}'
|
return ' '.join(parts)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'UPS主机'
|
verbose_name = 'UPS主机'
|
||||||
|
|||||||
Reference in New Issue
Block a user