Trey Hunner 🐍 on Nostr: Since you don't want values but actual model objects instead, you may need to use a ...
Since you don't want values but actual model objects instead, you may need to use a subquery.
This maybe?
subquery = (
ContainerBase.objects
.filter(cname=OuterRef('cname'))
.values('cname')
.annotate(max_ctime=Max('ctime'))
.values('max_ctime')
)
query = (
ContainerBase.objects
.annotate(max_ctime=Subquery(subquery))
.filter(ctime=F('max_ctime'))
.order_by('cname')
.distinct('cname')
)
Published at
2024-08-21 22:32:39Event JSON
{
"id": "503c6b59b73d7674b3f121044d0eb003d99c718dda9502920a2fc6f166c638b2",
"pubkey": "7e9159fbfd5526415c8d2de2e4c7654e3660883f9ccae720a70fa3c1f3cf1f45",
"created_at": 1724279559,
"kind": 1,
"tags": [
[
"e",
"8f6b8e19cbf5e7f397244f5e43cccd44939bfa190f25f56973c963eac6d03d2d",
"",
"root",
"3df3d89bb59a64ff75dd54697fd4b32aacd77fa3a90bcd893f733339015c2089"
],
[
"proxy",
"https://mastodon.social/@treyhunner/113002385226253018",
"web"
],
[
"p",
"3df3d89bb59a64ff75dd54697fd4b32aacd77fa3a90bcd893f733339015c2089"
],
[
"proxy",
"https://mastodon.social/users/treyhunner/statuses/113002385226253018",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mastodon.social/users/treyhunner/statuses/113002385226253018",
"pink.momostr"
],
[
"-"
]
],
"content": "Since you don't want values but actual model objects instead, you may need to use a subquery.\n\nThis maybe?\n\nsubquery = (\n ContainerBase.objects\n .filter(cname=OuterRef('cname'))\n .values('cname')\n .annotate(max_ctime=Max('ctime'))\n .values('max_ctime')\n)\n\nquery = (\n ContainerBase.objects\n .annotate(max_ctime=Subquery(subquery))\n .filter(ctime=F('max_ctime'))\n .order_by('cname')\n .distinct('cname')\n)",
"sig": "dafb36dc2452d2007d7766e78f5c405cae3493c3f178a3fcdb6f9cd27441c783cfbb10c5f6973f1b0591bd81c06d455606dfeeb4700b6c37590c7687465de428"
}