如何从查询中显示外键的名称?
<div class="container">
<table>
<thead>
<tr>
<th width="120px">First</th>
<th width="120px">Second</th>
<th width="120px">Third</th>
<th width="120px">Fourth</th>
<th width="120px">Fifth</th>
</tr>
</thead>
</table>
<div class="scroallable_div">
<table>
<thead>
<tr>
<th width="120px"></th>
<th width="120px"></th>
<th width="120px"></th>
<th width="120px"></th>
</tr>
</thead>
<tbody>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
<tr>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
<td>hgdfgdgfd</td>
</tr>
</tbody>
</table>
</div>
</div>
如何使查询显示类别名称而不是category_id?
谢谢
答案 0 :(得分:0)
Books.objects.filter(user=4).values('category__name').annotate(amount2=Sum('amount'))