Changeset 582 for trunk/telemeta/models/query.py
- Timestamp:
- 02/17/10 16:20:36 (7 months ago)
- Files:
-
- 1 modified
-
trunk/telemeta/models/query.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/telemeta/models/query.py
r580 r582 84 84 def by_location(self, location): 85 85 "Find items by location" 86 return self.filter( Q(location=location) | Q(location__in=location.descendants()))86 return self.filter(location__in=location.apparented()) 87 87 88 88 @staticmethod … … 93 93 from telemeta.models import Location, LocationRelation 94 94 l = self.values('location') 95 c = self.values('location__current_location') 95 96 r = LocationRelation.objects.filter(location__in=l).values('ancestor_location') 96 return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r) )97 return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r) | Q(pk__in=c)) 97 98 98 99 def countries(self, group_by_continent=False): … … 102 103 location = Location.objects.get(pk=id) 103 104 for l in location.countries(): 104 if not l in countries: 105 countries.append(l) 105 c = l.current_location 106 if not c in countries: 107 countries.append(c) 106 108 107 109 if group_by_continent: … … 226 228 def by_location(self, location): 227 229 "Find collections by location" 228 return self.filter( Q(items__location=location) | Q(items__location__in=location.descendants())).distinct()230 return self.filter(items__location__in=location.apparented()).distinct() 229 231 230 232 def by_recording_year(self, from_year, to_year=None): … … 352 354 return map 353 355 354 def current(self, is_current=True): 355 if is_current: 356 where = ["locations.id = locations.current_location_id"] 357 else: 358 where = ["locations.id <> locations.current_location_id"] 359 360 return self.extra(where = where); 356 def current(self): 357 return self.filter(id__in=self.values_list('current_location_id', flat=True)).distinct() 361 358 362 359 class LocationManager(CoreManager):
