views:

9

answers:

0

Hi,

I am writing a custom manager, and implementing the get_query_set method.

Basically, I want to see that certain fields are passed into the query, think the Custom Site Manager but not wanting to add filters I want to ensure that some fields ARE filtered on. Below is one way, but I was wondering if there is a better way to get the fields that will be constrained

class OrgBaseModelManager(models.Manager):
  def get_query_set(self):
    qs = super(OrgBaseModelManager, self).get_query_set()
    #Below returns a list of 
    constraint_lists = [c.children for c in qs.query.where.children]
    import itertools
    chain = itertools.chain(*constraint_lists)
    constraint_fields =  list(chain)

    #here is where I would do my magic        

    return super(OrgBaseModelManager, self).get_query_set() 

So my question is, to see if there is a better approach, I am concerned for very convoluted queries, that I have not flattend the tree properly.

Any ideas of better approaches?

Regards

Mark