Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Created December 21, 2012 17:32
Show Gist options
  • Save blackrobot/4354297 to your computer and use it in GitHub Desktop.
Save blackrobot/4354297 to your computer and use it in GitHub Desktop.
from django.db.models import Q
from apps.research.models import Product
"""
`codes` is a list of remaining (str) barcodes from the file.
`excludes` is a list of primary keys which i've already found
"""
minimum_digits = 5
qset = Q()
for code in codes:
if len(code) > minimum_digits:
qset |= Q(barcode__startswith=code) | Q(barcode__endswith=code)
print "Finished creating queryset"
products = Product.objects.exclude(pk__in=excludes).filter(qset).distinct()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment