2👍
✅
The change in the first line of your code goes unsaved, and then you’re just looping through the queryset and triggering save on model instances with no changes.
You’ll need to call save using the model instance on which you mutated state:
obj = LabHours.objects.filter(used=False).order_by("endtime").first()
obj.used = True
obj.save()
👤wim
1👍
This happened because you didn’t save the value that you updated.
first = LabHours.objects.filter(used=False).order_by("endtime").first()
first.used = True
first.save()
for hours in LabHours.objects.all():
hours.save()
print hours.used
👤2ps
- [Django]-How to implement password change form in Django 1.9
- [Django]-AttributeError: 'CharField' object has no attribute 'model'
- [Django]-Does any one know of an RTF report generator in Django?
- [Django]-Django Model: Meta: how to have default ordering case-insensitive
- [Django]-Django local_settings import error
Source:stackexchange.com