Hi Ian, On Apr 20, 5:33 pm, Ian Clelland <clell...@gmail.com> wrote: > It sounds like you could do this with a QuerySet.extra() call > (http://docs.djangoproject.com/en/1.3/ref/models/querysets/#extra) >
> You could do something like: > myModel.objects.filter(title__icontains="test").extra( > where='oe_matches(structure.smiles, > "[C;!H0]")') Interesting. I saw that, but didn't figure out that it might do what I want. I don't think it's possible though, and that's because I didn't explain the complexity. (I thought I could get away with less.) What I have is actually like this: I have a discussion thread with a "question" node and "answer" nodes. Each node can have one or more structures. Each structure can be in one or more node. This is a many-to-many join through an intermediate table. Nodes have "title" and "body." The structure is in the structure table "smiles" column. My search is to find all questions such that: (the word "test" is in the title or body of the question node AND the substructure"[C;!H0]" exists in any of the structures linked to this node) OR (the word "test" is in the title or body of any of its children nodes AND the substructure ".." exists in one of the child node's structures) I did something like this using a lot of LEFT OUTER JOIN, and it seems to work although I think I don't yet have the logic right and this will need more testing ... and review by someone who actually knows SQL. The problem is that I have two ways to get to structure.smiles, one through the parent question and another through the children answers. My left outer join does an alias for one of those. I learned the syntax by seeing what Django does for that case. This means my extra() call would need to know the alias Django uses for making the call, and that's not available programmatically. I could hard code it to "T6" or whatever, but that's very much a hack. (Although it might still be cleaner than my 40 lines of SQL generation code.) Andrew Dalke da...@dalkescientific.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.