def affected_areas(self): with_disasters = flatten(self.queryset.values_list('locations')) return len(set(with_disasters))
def get_location(self, obj): locations = Location.objects(id__in=obj.target_locations) if locations.filter(type='subcounty'): return locations districts_children = [district.children() for district in locations] return flatten(districts_children)
def test_empty_is_discarded_when_flatten_list(self): list_=[[1,2],[], [4,5,6], [], [8,9]] self.assertEqual([1,2,4,5,6,8,9], flatten(list_))
def test_flatten_list(self): list_=[[1,2,3],[4,5,6], [7], [8,9]] self.assertEqual([1,2,3,4,5,6,7,8,9], flatten(list_))