Skip to content

Commit

Permalink
Changed behavior of (de)activating an item within the change form:
Browse files Browse the repository at this point in the history
Instead of changing all descendants' active status to the current item's, it will only change the descendants' active status if the item is False.

As it makes sense to have an item active, but its children inactive, it doesn't make sense that an item is inactive, but its descendants are active.

This doesn't change the activate/deactivate admin actions. They will always  affect an item and its descendants.
  • Loading branch information
coordt committed Jan 5, 2012
1 parent 11481db commit 416898d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ def save(self, *args, **kwargs):

super(Category, self).save(*args, **kwargs)

for item in self.get_descendants():
if item.active != self.active:
item.active = self.active
item.save()
# While you can activate an item without activating its descendants,
# It doesn't make sense that you can deactivate an item and have its
# decendants remain active.
if not self.active:
for item in self.get_descendants():
if item.active != self.active:
item.active = self.active
item.save()

class Meta:
verbose_name_plural = 'categories'
Expand Down

0 comments on commit 416898d

Please sign in to comment.