Hi!
Thank you for your response.
I will try to describe my problem more precisely.
In model.py file there are the following classes:
class Base((InheritableSQLObject):
created = DateTimeCol(default=DateTimeCol.now())
class BaseSample(Base):
name = StringCol(length=40, alternateID=True)
class BaseData(Base):
sample_id = ForeignKey("BaseSample")
On the web page user must have opportunite to find samples.
The fields for seach are described in controller.py file:
def sample_search(self, tg_errors=None, **kwarg):
order_list = [('name', 'sample name'),
('created', 'time of recording')]
# fields in search form:
name = widgets.TextField(name='name', label='Sample name')
before = widgets.CalendarDateTimePicker(name='before',
label='Created before,
convert=True)
order = widgets.SingleSelectField(name='order', label='Order
by',
options=order_list)
if kwarg.has_key('order'):
if str(kwarg['order']) == 'name':
order_by = model.BaseSample.q.name
if str(kwarg['order']) == 'created':
order_by = model.Base.q.created
result = [list(model.BaseSample.select(query, distinct=True,
orderBy=order_by))]
...
query consists criteria for sample search. If one selected
orderBy = model.Base.q.created, TG gives the following error:
ProgrammingError: ERROR: for SELECT DISTINCT, ORDER BY expressions
must appear in select list
SELECT DISTINCT base_sample.id, base_sample.child_name,
base_sample.name
FROM base, base_sample
WHERE ((((base_sample.name) LIKE ('%S%'))) AND ((base_sample.id) =
(base.id)))
ORDER BY base.created
How I can add the fields in select list?
I tried to resolve this problem with Select(SQLExpresion). In this
case I can't define distict (it also important for my task), because
Select hasn't parameter distinct.
Best regards
Svetlana
On 26 Feb., 13:38, "Diez B. Roggisch" <[EMAIL PROTECTED]>
wrote:
> On Monday 26 February 2007 11:41, svetl wrote:
>
>
>
> > Good day!
> > If you have any idea how to resolve the following
> > problem, please, help me. Thanks in advance.
> > I have in model.py file
> > class Base(InheritableSQLObject):
> > .....
> > created = DateTimeCol(default=DateTimeCol.now())
> > .....
> > class BaseSample(Base):
> > name = StringCol(length=40, alternateID=True)
>
> > I have to search samples and to sort them by date.
> > The function seach defined in controllers.py containes the query:
> > def search(self):
> > ....
> > model.BaseSample.select(AND(CONTAINSSTRING(model.BaseSample.q.name,
> > "something",
> > model.Base.created =='12.12.06')), orderBy=model.Base.created)
>
> > It gives an error and I undestand why. Because this select query
> > generates the following:
> > SELECT * FROM tables base_sampl, base WHERE.....
> > The fields (*) in SELECT query are all from table 'base_sample'. In
> > this place
> > there are no fields from table Base, but orderBy needs the explicit
> > field name
> > from table 'base' (class Base).
>
> The above clearly isn't what you actually have in your code, or it gives you a
> different error altogether. Because you miss the model.Base.q several times.
>
> Please verify that you really have working code.
>
> Apart from that, it should work like this (note the usage of Base
>
> model.Base.select(AND(<your-criteria>, model.Base.q.childName
> == 'BaseSample'), orderBy=model.Base.q.created)
>
> Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---