Exemplo n.º 1
0
    def _delete(self, id):
        c.product = Product.find_by_id(id)
        for include in ProductInclude.find_by_product(id):
            meta.Session.delete(include)
        meta.Session.commit()
        meta.Session.delete(c.product)
        meta.Session.commit()

        h.flash("Product has been deleted.")
        redirect_to('index')
Exemplo n.º 2
0
    def _delete(self, id):
        c.product_category = ProductCategory.find_by_id(id)
        # For some reason cascading isn't working for me. Likely I just don't understand SA so I'll do it this way:
        # first delete all of the products
        for product in c.product_category.products:
            # We also delete all of the productincludes for the products
            for include in ProductInclude.find_by_product(product.id):
                meta.Session.delete(include)
            meta.Session.commit()
            meta.Session.delete(product)
        meta.Session.commit()
        # Also delete any includes of the category
        for include in ProductInclude.find_by_category(id):
            meta.Session.delete(include)
        meta.Session.commit()
        meta.Session.delete(c.product_category)
        meta.Session.commit()

        h.flash("Category has been deleted.")
        redirect_to('index')