class DeveloperManager models Manager def with_estates self developers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class DeveloperManager(models.Manager):
def with_estates(self):
developers = self.get_query_set().all()
d_ids = [d.id for d in developers]
all_estates = EstateItem.objects\
.prefetch_related('developer', 'district', 'preview_image',
'metro__metro', 'metro__mode')
estates = all_estates.filter(developer__in=d_ids, active=True)
#estate_sell = all_estates.filter(other_developer__in=d_ids, active=True)
for d in developers:
d.estates = filter(lambda e: e.developer_id == d.id, estates)
#d.estate_sell = filter(lambda e: d.id in [_.id for _ in e.other_developer.all()], estate_sell)
return developers