Created
December 21, 2012 17:32
-
-
Save blackrobot/4354297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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