What should I do to change the ID(1, 2) displayed on the admin site to the name(tire, wheel), like the attached image?
html
<tbody>
{% for row in summary11 %}
<tr class="{% cycle 'row1' 'row2' %}"></tr>
<td> {{ row.category__parent }} </td>
<td> {{ row.total }} pcs </td>
{% endfor %}
</tbody>
models.py
class ParentCategory(models.Model):
name = models.CharField('Parts Name', max_length=255)
def __str__(self):
return self.name
class Category(models.Model):
name = models.CharField('Problem', max_length=255)
parent = models.ForeignKey(ParentCategory, verbose_name='Parts Name',
on_delete=models.PROTECT)
def __str__(self):
return self.name
class Post(models.Model):
category = models.ForeignKey(Category, verbose_name='Problem',
on_delete=models.PROTECT)
Quantity = models.IntegerField(default=1, verbose_name ="QTY: Used for Repair")
Quantity_New = models.IntegerField(default=0,verbose_name ="QTY: Arrived for Inventry")
Data = models.DateField(default=timezone.now, verbose_name='Date')
def __str__(self):
return self.category
class PartsSummary(Post):
class Meta:
proxy = True
verbose_name = 'Parts_Summary'
verbose_name_plural = 'Parts_Summary'
Admin.py
class PartsSummaryAdmin(admin.ModelAdmin):
change_list_template = 'admin/parts_summary_change_list.html'
date_hierarchy = 'Data'
def changelist_view(self, request, extra_context=None):
response = super().changelist_view(
request,
extra_context=extra_context,
)
try:
qs = response.context_data['cl'].queryset
except (AttributeError, KeyError):
return response
metrics = {
'total': Sum('Quantity'),
}
response.context_data['summary11'] = list(
qs
.values('category__parent')
.annotate(**metrics)
.order_by('category__parent')
)