summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-27 11:07:22 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-27 11:07:22 +0200
commit9e477fbeb6e9fb811968f31f937df5877b816aa7 (patch)
treea74db58ad7084e3e3ca5654bb9a89a4340b3c20e /chimere/models.py
parent63bb46ac8b05c7184c9ee50e7a76894b8722db52 (diff)
downloadChimère-9e477fbeb6e9fb811968f31f937df5877b816aa7.tar.bz2
Chimère-9e477fbeb6e9fb811968f31f937df5877b816aa7.zip
Fix property model filtering on edit pages
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/chimere/models.py b/chimere/models.py
index 25b599b..8ab0b22 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -581,10 +581,12 @@ class GeographicItem(models.Model):
"""Get all the property availables
"""
properties = []
- for pm in PropertyModel.getAvailable(area_name=area_name):
- property = self.getProperty(pm)
- if property:
- properties.append(property)
+ querys = PropertyModel.getAvailable(area_name=area_name)
+ for query in querys:
+ for pm in query.all():
+ property = self.getProperty(pm)
+ if property:
+ properties.append(property)
return properties
def setProperty(self, pm, value):
@@ -1855,14 +1857,16 @@ class PropertyModel(models.Model):
def getAvailable(cls, area_name=None):
if area_name and area_name.endswith('/'):
area_name = area_name[:-1]
- q = cls.objects.filter(available=True)
+ base_q = cls.objects.filter(available=True).annotate(Count('areas'))
+ q1 = base_q.filter(areas__count=0)
if not area_name:
- return q.annotate(Count('areas')).filter(areas__count=0)
+ return [q1]
# areas__count__gt=0 necessary to prevent Django bug
- return q.annotate(Count('areas'))\
- .filter(
- (Q(areas__urn=area_name) & Q(areas__count__gt=0)) |
- Q(areas__count=0))
+ q2 = base_q.filter(Q(areas__urn=area_name) & Q(areas__count__gt=0))
+ # if made it a single queryset the condition on 'count' is
+ # wrong - hope this will be fixed on higher Django version (>=1.4)
+ # to make a single query
+ return [q1, q2]
class PropertyModelChoice(models.Model):