On Aug 12, 2011, at 10:21 AM, RVince wrote:
> I'm trying to discern a means of creating a .filter(A rel B) where the
> values for A, rel and B come from an parameters passed in to the web
> page.
>
> I already have an SQLAlchemy statement, say
> query = Session.query(table).filter(A==B)
>
> and I want to be able to allow for a "drilldown" of sorts by the, such
> that from the web page they can pick a value from a dropdown, a
> relation (from a dropdown) and a textbox to compare to. But my problem
> is once I have these three values, how do I get them into
> the .filter() function? That's not going to merely accept string
> values -- is there a way to do this?
>
> Thanks, RVince
>
You can build your SQLAlchemy queries dynamically, i.e.
q1 = query.Session.query(table).filter(A == B)
q2 = q1.filter(C == D)
q3 = q2.filter(E == F)
you could apply different relationships using conditional Python statements:
if rel == 'eq':
q4 = q3.filter(G == H)
elif rel == 'neq':
q4 = q3.filter(G != H)
is this what you're looking for?
Mark
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.