[Answer]-Sort Django objects by method with arguments

1👍

The easiest way to solve this is to use a keyword parameter in your lambda:

user = User.objects.get(username="jamie")
sorted(Task.objects.all(), key = lambda task, user=user: task.date_for_display(user))

This copies the user from the outer scope into the local scope of your lambda.

👤Marcin

Leave a comment