1. Jesper Nøhr
  2. django-piston


Jesper Nøhr  committed f8a0dfc

any() fallback for <2.5, checking both f.attname and f.name for method overwrites

  • Participants
  • Parent commits 4a47ab5
  • Branches default

Comments (0)

Files changed (1)

File piston/emitters.py

View file
 except ImportError:
     yaml = None
+# Fallback since `any` isn't in Python <2.5
+    any
+except NameError:
+    def any(iterable):
+        for element in iterable:
+            if element:
+                return True
+        return False
 from django.db.models.query import QuerySet
 from django.db.models import Model, permalink
 from django.utils import simplejson
                 met_fields = self.method_fields(handler, get_fields)
                 for f in data._meta.local_fields:
-                    if f.serialize and f.attname not in met_fields:
+                    if f.serialize and not any([ p in met_fields for p in [ f.attname, f.name ]]):
                         if not f.rel:
                             if f.attname in get_fields:
                                 ret[f.attname] = _any(v(f))