]> git.parisson.com Git - telemeta.git/commitdiff
begin to fix search by instrument
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Apr 2013 15:13:49 +0000 (17:13 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Apr 2013 15:13:49 +0000 (17:13 +0200)
telemeta/models/query.py
telemeta/views/home.py

index 7a078819258a8d23b18e12228e76fce5e5e05153..de634b79e1f169b75cdd0315ad6c39cdb8e5510e 100644 (file)
@@ -203,9 +203,16 @@ class MediaItemQuerySet(CoreQuerySet):
     def sound_public(self):
         return self.filter(file__contains='/', public_access='full', collection__public_access='full')
 
-    def by_instrument(self, instrument):
+    def by_instrument(self, name):
         "Find items by instrument"
-        return self.filter(instruments__in=instrument)
+        from telemeta.models.instrument import Instrument
+        instruments = Instrument.objects.filter(name=name)
+        items = []
+        for instrument in instruments:
+            performances = instrument.performances.all()
+            for performance in performances:
+                items.append(performance.media_item)
+        return items
 
 
 class MediaItemManager(CoreManager):
@@ -346,9 +353,16 @@ class MediaCollectionQuerySet(CoreQuerySet):
     def sound(self):
         return self.filter(items__file__contains='/').distinct()
 
-    def by_instrument(self, instrument):
+    def by_instrument(self, name):
         "Find collections by instrument"
-        return self.filter(items__instruments__in=instrument).distinct()
+        from telemeta.models.instrument import Instrument
+        instruments = Instrument.objects.filter(name=name)
+        items = []
+        for instrument in instruments:
+            performances = instrument.performances.all()
+            for performance in performances:
+                items.append(performance.media_item)
+        return self.filter(items__in=items).distinct()
 
 
 class MediaCollectionManager(CoreManager):
index 380ec2691f14ae72507c498eb7c18c534bdd96c4..f0d365bdf61237d72233395440ddcd0f7c795727 100644 (file)
@@ -254,7 +254,7 @@ class HomeView(object):
         return list_detail.object_list(request, objects,
             template_name='telemeta/search_results.html', paginate_by=20,
             extra_context={'criteria': criteria, 'collections_num': collections.count(),
-                'items_num': items.count(), 'corpus_num': corpus.count(), 'fonds_num': fonds.count(),
+                'items_num': len(items), 'corpus_num': corpus.count(), 'fonds_num': fonds.count(),
                 'type' : type,})
 
     def complete_location(self, request, with_items=True):