Suppose we have a table:
+--------------- ...
| id | old_id |
+--------------- ...
| ...
How do I select all values by some custom criteria except where id is found in column old_id?
I've tried:
records = MyRecords.objects\
.filter(<my custom criteria>)\
.exclude(id__in=models.OuterRef('old_id'))\
.order_by('-modified_at')
and other variations, but to no avail.
Basically, I am trying to achieve this behavior:
select * from mytable where
<custom criteria> and
not id in (select old_id from mytable where 1)