I have the following code that allows me to find images of equal has (identical), but say I wanted to just find images with a hamming distance under a certain number, can that be incorporated into django querysets, or raw sql somehow? I don't want to fetch everything and compare with python because that's very very slow and I many many images.
Current code:
def duplicates(request):
duplicate_images = []
images = Image.objects.all()
for image in images:
duplicates = Image.objects.filter(hash=image.hash).exclude(pk=image.pk)
for duplicate in duplicates:
duplicate_images.append([image, duplicate])
if len(duplicate_images) > 1000:
break