from django.db.models import QuerySet
import attr
from attr.validators import instance_of
@attr.s
class ChildDeactivate(object):
loca = attr.ib(validator=instance_of(QuerySet))
def deactivate_child(self,l):
get_parent = Boundary.objects.filter(parent__id=
l.id)
if get_parent:
deact_child = map(lambda x: x.switch(),get_parent)
else:
l.switch()
return
l.name, l.get_active_display(), l.boundary_level
def list_all(self):
for i in self.loca:
name_bound, status, level = self.deactivate_child(i)
print '{} is change to {} status of level {}'.format(name_bound, status, level)
l = Boundary.objects.filter(parent__id=2)
s = ChildDeactivate(l)
s.list_all()
In my location models i have 9 levels, i wrote this snippet to deactivate children objects when parent is deactivated, so anything to do to make it more generic all the over models..?