Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 29th, 2011  |  syntax: Python  |  size: 3.19 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jpk@truth:~/code/junkyard/geodjango_orm_bug$ ./manage.py shell_plus
  2. From 'auth' autoload: Permission, Group, User, Message
  3. From 'contenttypes' autoload: ContentType
  4. From 'sessions' autoload: Session
  5. From 'sites' autoload: Site
  6. From 'myapp' autoload: Spot, Property
  7. Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
  8. [GCC 4.6.1] on linux2
  9. Type "help", "copyright", "credits" or "license" for more information.
  10. (InteractiveConsole)
  11. >>> Spot.objects.all()
  12. [<Spot: id: 1>, <Spot: id: 2>, <Spot: id: 3>, <Spot: id: 4>]
  13. >>> Property.objects.all()
  14. [<Property: belonging to Spot 1>, <Property: belonging to Spot 2>, <Property: belonging to Spot 3>, <Property: belonging to Spot 4>]
  15. >>> spots = Spot.objects.all()
  16. >>> props = Property.objects.filter(spot__in=spots)
  17. >>> spots
  18. [<Spot: id: 1>, <Spot: id: 2>, <Spot: id: 3>, <Spot: id: 4>]
  19. >>> props
  20. [<Property: belonging to Spot 1>, <Property: belonging to Spot 2>, <Property: belonging to Spot 3>, <Property: belonging to Spot 4>]
  21. >>> for p in props:
  22. ...     print p
  23. ...
  24. belonging to Spot 1
  25. belonging to Spot 2
  26. belonging to Spot 3
  27. belonging to Spot 4
  28. >>> from django.contrib.gis.geos import Polygon
  29. >>> northern_hemisphere = Polygon(( (-180,90),(180,90),(180,0),(-180,0),(-180,90)  ))
  30. >>> spots = Spot.objects.filter(location__contained=northern_hemisphere)
  31. >>> spots
  32. [<Spot: id: 1>, <Spot: id: 2>]
  33. >>> props = Property.objects.filter(spot__in=spots)
  34. >>> props
  35. []
  36. >>> for p in props:
  37. ...     print p
  38. ...
  39. Traceback (most recent call last):
  40.   File "<console>", line 1, in <module>
  41.   File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 107, in _result_iter
  42.     self._fill_cache()
  43.   File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 772, in _fill_cache
  44.     self._result_cache.append(self._iter.next())
  45.   File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 273, in iterator
  46.     for row in compiler.results_iter():
  47.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 680, in results_iter
  48.     for rows in self.execute_sql(MULTI):
  49.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 725, in execute_sql
  50.     sql, params = self.as_sql()
  51.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 68, in as_sql
  52.     where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
  53.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 92, in as_sql
  54.     sql, params = child.as_sql(qn=qn, connection=connection)
  55.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 95, in as_sql
  56.     sql, params = self.make_atom(child, qn, connection)
  57.   File "/usr/lib/pymodules/python2.7/django/contrib/gis/db/models/sql/where.py", line 50, in make_atom
  58.     return super(GeoWhereNode, self).make_atom(child, qn, connection)
  59.   File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 166, in make_atom
  60.     if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
  61.   File "/usr/lib/pymodules/python2.7/django/contrib/gis/db/backends/postgis/adapter.py", line 24, in __eq__
  62.     return (self.ewkb == other.ewkb) and (self.srid == other.srid)
  63. AttributeError: 'str' object has no attribute 'ewkb'
  64. >>>
  65.  
  66.