Fix battery count display - show total quantity instead of record count
This commit is contained in:
@@ -44,6 +44,10 @@ class UPSHost(models.Model):
|
|||||||
created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
||||||
updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
|
updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total_battery_count(self):
|
||||||
|
return sum(battery.quantity for battery in self.battery_set.all())
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
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}'
|
return f'{self.brand} {self.model} - {self.ip_address}'
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<td>{{ ups.ip_address }}</td>
|
<td>{{ ups.ip_address }}</td>
|
||||||
<td>{{ ups.quantity }}</td>
|
<td>{{ ups.quantity }}</td>
|
||||||
<td>{{ ups.location }}</td>
|
<td>{{ ups.location }}</td>
|
||||||
<td><span class="badge bg-success">{{ ups.battery_set.count }}</span></td>
|
<td><span class="badge bg-success">{{ ups.total_battery_count }}</span></td>
|
||||||
<td>{{ ups.last_maintenance_date|default:"-" }}</td>
|
<td>{{ ups.last_maintenance_date|default:"-" }}</td>
|
||||||
<td>{{ ups.contact|default:"-" }}</td>
|
<td>{{ ups.contact|default:"-" }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user