2👍
✅
You can set the attribute of an object any time your want:
import random
objects = []
for obj in MyModel.objects.all():
obj.score = random.randint(0, 100)
objects.append(obj)
sorted_objects = sorted(objects, key=lambda x: x.score)
0👍
import random
sorted_objects = sorted(map(lambda x: x.score = random.randint(0,100),MyModel.objects.all()),key = lambda x:x.score)
- [Answered ]-Django: manage.py works fine but django-admin fails
- [Answered ]-Django – Ajax request on mobile giving 403 forbidden even when CSRF token is set
- [Answered ]-Adding newrelic to a python stack (django) deployed via dokku
- [Answered ]-Does Django Channels work as intended as a WSGI app?
Source:stackexchange.com