Last active
August 29, 2015 14:13
-
-
Save soukiassianb/b8fb172a7ddcad12906c to your computer and use it in GitHub Desktop.
Filter product by tag [TaggedProduct classmethod]
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
class TaggedProducts(GenericTaggedItemBase): | |
[...] | |
# filter products by tags | |
@classmethod | |
def filter(cls, *tags): | |
products = Products.objects.all() | |
for tag in tags: | |
if tag not in (t.slug for t in ProductTags.objects.all()): # not good for speed | |
return "%s tag does not exists, please try with valid tags" % (tag) | |
products = products.filter(tags__slug__in=[tag]) | |
return products if len(products) > 0 else "No products tagged with %s" % (", ".join(tags)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment