google-code-export / djapian

Automatically exported from code.google.com/p/djapian
Other
1 stars 0 forks source link

Add a recursive field resolver #116

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Let's say you have this hierarchy of models and I want to index the hostname 
and *all* the installations on each of the disks and slots of that specific 
host. Well, it doesn't seem to work. After looking at indexer.Field.resolve() I 
noticed there's no recursion at all, it's meant to handle only 2 levels of 
relationships.

Tip: did you look at django-piston's solution to this ?
http://bitbucket.org/jespern/django-piston/src/tip/piston/emitters.py#cl-90

# models.py
class Host(models.Model):
    hostname = models.CharField()

class Disk(models.Model):
    host = models.ForeignKey(Host)

class Slot(models.Model):
    disk = models.ForeignKey(Disk)

class Installation(models.Model):    
    slot = models.OneToOneField(Slot)
    product = models.CharField()

# index.py
class HostIndexer(Indexer):
   tags = [
       ('hostname', 'hostname'),
       ('product', 'disk_set.slot_set.installation.product'), # <-- Not working
   ]
space.add_index(Host, HostIndexer, attach_as='indexer')

Original issue reported on code.google.com by jonsibo...@gmail.com on 6 Jul 2010 at 10:29