13. How to find distinct field values from queryset?ΒΆ


You want to find users whose names have not been repeated. You can do this like this

distinct = User.objects.values(
records = User.objects.filter(first_name__in=[item['first_name'] for item in distinct])

This is different from User.objects.distinct("first_name").all(), which will pull up the first record when it encounters a distinct first_name.