Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created March 14, 2012 18:18
Show Gist options
  • Save andymccurdy/2038383 to your computer and use it in GitHub Desktop.
Save andymccurdy/2038383 to your computer and use it in GitHub Desktop.
cat_to_remove = <category_publishable_is_being_removed_from>
categories = [all_current_leaf_categories_publishable_is_in];
categories.remove(cat_to_remove);
all_cats = set()
for cat in categories:
while cat:
all_cats.add(cat)
cat = cat.parent
# all_cats should now be a set of all categories the publishable should still be in after the removal
while cat_to_remove:
if cat_to_remove in all_cats:
continue
remove(pub.id, cat_to_remove)
cat_to_remove = cat_to_remove.parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment