def get_categories(self, with_parents=False):
        cache_key = "%s-product-categories-%s-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, self.id, with_parents)
        categories = cache.get(cache_key)

        if categories is not None:
            return categories

        object = self.get_parent()

        if with_parents:
            categories = []
            for category in object.categories.all():
                while category:
                    categories.append(category)
                    category = category.parent
            categories = categories
        else:
            categories = object.categories.all()

        cache.set(cache_key, categories)
        return categories
Returns the categories of the product.
dataset/ETHPy150Open diefenbach/django-lfs/lfs/catalog/models.py/Product.get_categories