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.

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]")


Of the two forms I gave, I prefer the first since I could see the
implementation being something simple like:

class smartsmatch(object):
  def __init__(self, smarts):
    self.smarts = smarts
  def as_sql(self, column):
    return ("oe_matches(%s, %s)", (column, smarts))


I looked but found nothing in the documentation or on the way for how
to access user-defined function in Django except through the raw()
interface.

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.

Reply via email to