On Wed, Apr 20, 2011 at 8:18 AM, Andrew Dalke <andrewda...@gmail.com> wrote:
> I'm using MySQL and sometimes SQLite as the backend database. Both > databases let me add user-defined functions. I've made a set of UDFs > specific to my problem domain, which is chemsitry. > > How do I call them from a database query? Currently I'm using a raw() > call, which made for some rather ugly SQL construction. > It sounds like you could do this with a QuerySet.extra() call ( http://docs.djangoproject.com/en/1.3/ref/models/querysets/#extra) I don't know how you would use those with Q objects, though. > > Ideally I would like something like > > q = (models.Q(title__icontains="test") & > models.Q(structure_smiles = smartsmatch(smarts="[C;!H0]")) > > -or- > > q = (models.Q(title__icontains="test") & > models.Q(structure_smiles__smartsmatch = "[C;!H0]")) > > > which would get mapped to > > title LIKE 'test' AND structure_id = structure.id AND > oe_matches(structure.smiles, "[C;!H0]") > > You could do something like: myModel.objects.filter(title__icontains="test").extra(where='oe_matches(structure.smiles, "[C;!H0]")') You could encapsulate the extra() call in a function call that annotates a QuerySet that you pass to it, but it's 'outside' of the ORM at that point. -- Regards, Ian Clelland <clell...@gmail.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.