I have been trying to select all the objects that do not have an associated OneToOne? field.
- M.objects.filter fails to select the correct objects - either selects everything or nothing.
- M.objects.exclude generates incorrect SQL - missing the table name, eg:
Failed example:
Place.objects.exclude(restaurant__isnull=True)
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python2.5/site-packages/django/test/_doctest.py", line 1267, in __run
compileflags, 1) in test.globs
File "<doctest modeltests.one_to_one.models.__test__.API_TESTS[41]>", line 1, in <module>
Place.objects.exclude(restaurant__isnull=True)
File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 43, in __repr__
return repr(list(self))
File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 55, in __len__
self._result_cache.extend(list(self._iter))
File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 162, in iterator
for row in self.query.results_iter():
File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 200, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 1466, in execute_sql
cursor.execute(sql, params)
ProgrammingError: syntax error at or near "WHERE"
LINE 1: ...N (SELECT "one_to_one_restaurant"."place_id" FROM WHERE "one...
The following are additional cases for the unit tests in modeltests/one_to_one/models.py:
>>> p3 = Place.objects.create(name="Not A Restaurant", address="123 Fake St")
>>> Place.objects.filter(restaurant__exact=None)
[<Place: Not A Restaurant the place>]
>>> Place.objects.filter(restaurant__isnull=True)
[<Place: Not A Restaurant the place>]
>>> Place.objects.filter(restaurant__isnull=False)
[<Place: Demon Dogs the place>, <Place: Ace Hardware the place>]
>>> Place.objects.exclude(restaurant__isnull=True)
[<Place: Demon Dogs the place>, <Place: Ace Hardware the place>]
>>> Place.objects.exclude(restaurant__isnull=False)
[<Place: Not A Restaurant the place>]
I am using Ubuntu 7.10, Python 2.5.1, post QSRF Trunk Django, and Postgres 8.1