update prefetched fields

This commit is contained in:
j3d1 2024-11-29 01:32:54 +01:00
parent c03d298a58
commit ec6e872163
4 changed files with 23 additions and 7 deletions

View file

@ -32,7 +32,11 @@ class Item(SoftDeleteModel):
@property
def container(self):
try:
return self.container_history.order_by('-timestamp').first().container
history = sorted(self.container_history.all(), key=lambda x: x.timestamp, reverse=True)
if history:
return history[0].container
else:
return None
except AttributeError:
return None