How to join non-relational models in Django 1.3 on 2 fields -
i've got 2 existing models need join non-relational (no foreign keys). these written other developers cannot modified me.
here's quick description of them:
model process
- field filename
- field path
- field somethingelse
- field bar
model service
- field filename
- field path
- field servicename
- field foo
i need join instances of these 2 models on filename , path columns. i've got existing filters have apply each of them before join occurs.
example:
a = process.objects.filter(somethingelse=231)
b = service.objects.filter(foo='abc')
result = a.filter(filename=b.filename,path=b.path)
this sucks, best bet iterate models of 1 type, , issue queries joined models other type.
the other alternative run raw sql query perform these joins, , retrieve ids each model object, , retrieve each joined pair based on that. more efficient @ run time, need manually maintained if schema evolves.
Comments
Post a Comment