Reputation: 421
I have a model which has a latest
field to determine if a particular instance is the latest definition.
When adding a new row to the db I want to make sure to mark latest
as false for the already existing record.
latest_version = Segment.objects.filter(title=title, latest=True).first()
if latest_version:
latest_version.latest = False
latest_version.save()
This seems relatively straight forward but the latest
field will not update and stays as True
.
Upvotes: 1
Views: 519
Reputation: 1793
I think you are looking at the wrong object for the update. I think what you are looking for is:
Segment.objects.filter(title=title, latest=True).last()
Upvotes: 1