]> git.parisson.com Git - telemeta.git/commitdiff
fix intrument search
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Apr 2013 22:12:22 +0000 (00:12 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Apr 2013 22:12:22 +0000 (00:12 +0200)
telemeta/models/query.py

index de634b79e1f169b75cdd0315ad6c39cdb8e5510e..1c51119dd96e70fe2915fca38b5befb503528f91 100644 (file)
@@ -206,14 +206,15 @@ class MediaItemQuerySet(CoreQuerySet):
     def by_instrument(self, name):
         "Find items by instrument"
         from telemeta.models.instrument import Instrument
-        instruments = Instrument.objects.filter(name=name)
-        items = []
-        for instrument in instruments:
-            performances = instrument.performances.all()
+        from telemeta.models.media import MediaItemPerformance
+        instruments = Instrument.objects.filter(name__contains=name)
+        print instruments
+        if instruments:
+            perf = []
+            performances = MediaItemPerformance.objects.filter(instrument__in=instruments)
             for performance in performances:
-                items.append(performance.media_item)
-        return items
-
+                perf.append(performance)
+            return self.filter(performances__in=perf).distinct()
 
 class MediaItemManager(CoreManager):
     "Manage media items queries"
@@ -356,7 +357,7 @@ class MediaCollectionQuerySet(CoreQuerySet):
     def by_instrument(self, name):
         "Find collections by instrument"
         from telemeta.models.instrument import Instrument
-        instruments = Instrument.objects.filter(name=name)
+        instruments = Instrument.objects.filter(name__contains=name)
         items = []
         for instrument in instruments:
             performances = instrument.performances.all()