def soft_delete(self, user=None): if not self.status == CategoryStatus.DELETED: for shop_product in self.primary_shop_products.all(): shop_product.categories.remove(self) shop_product.primary_category = None shop_product.save() for shop_product in self.shop_products.all(): shop_product.categories.remove(self) shop_product.primary_category = None shop_product.save() for child in self.children.all(): child.parent = None child.save() self.status = CategoryStatus.DELETED self.add_log_entry("Deleted.", kind=LogEntryKind.DELETION, user=user) self.save() category_deleted.send(sender=type(self), category=self)
def soft_delete(self, user=None): if not self.status == CategoryStatus.DELETED: for shop_product in self.primary_shop_products.all(): shop_product.categories.remove(self) shop_product.primary_category = None shop_product.save() for shop_product in self.shop_products.all(): shop_product.categories.remove(self) shop_product.primary_category = None shop_product.save() for child in self.children.all(): child.parent = None child.save() self.status = CategoryStatus.DELETED self.add_log_entry("Success! Deleted (soft).", kind=LogEntryKind.DELETION, user=user) self.save() category_deleted.send(sender=type(self), category=self)