我想在一个查询中获取所有数据,因此我需要通过相关过滤器(而不是父对象过滤器)从相关对象添加一些字段结果。
def get_queryset(self):
return Mailbox.objects\
.filter(owner=self.request.user.id)\
.prefetch_related('letter_set')\
.annotate(
new_letter_count=Count(
'letter',
filter=Q(letter__read_at=None)
),
total_count=Count('letter'),
latest_letter_datetime=Max('letter__created_at'),
### #################### ###
### THE QUESTION IS HERE ###
### #################### ###
latest_letter_CONTENT= #(What code here could be work?)#
### I wnat to get the latest letter content
)