Ticket #8039: bug.py

File bug.py, 1.4 KB (added by anonymous, 16 years ago)
Line 
1#encoding= utf-8
2from django.db import models
3from django.contrib.auth.models import User
4
5Order(models.Model):
6 created_by = models.ForeignKey(User)
7 text = models.TextField()
8
9searchstring = 'Lara' #some user that exists and has orders
10
11orders = Order.objects.all()
12orders = orders.extra(where=[u"((first_name||' '||last_name) ILIKE '%%'|| %s ||'%%' or username = %s)",
13 u"(auth_user.id = core_order.created_by_id OR auth_user.id = core_order.last_modified_by_id)"],
14 params=[searchstring, searchstring],
15 tables=['auth_user'])
16
17print orders.query.as_sql()
18orders = orders.order_by('-created_by')
19
20print orders #This works fine
21
22orders = Order.objects.all()
23orders = orders.extra(where=[u"((first_name||' '||last_name) ILIKE '%%'|| %s ||'%%' or username = %s)",
24 u"(auth_user.id = core_order.created_by_id OR auth_user.id = core_order.last_modified_by_id)"],
25 params=[searchstring, searchstring],
26 tables=['auth_user'])
27#Omitting as_sql() this time
28orders = orders.order_by('-created_by')
29
30print orders
31Traceback (most recent call last):
32 File "<console>", line 1, in <module>
33...
34ProgrammingError: column "first_name" does not exist
35LINE 1: ..."."last_modified_by_id" FROM "core_order" WHERE ((first_name...
36
Back to Top