views:

35

answers:

1

I was wondering if there a way I can pass two or more variables in a custom manager...there are five variables that come from different views but in the model, I've declared a manager to handle filtering based on one of these variables...I want to have all the variables being considered in the filter query. Is there a way to do this?

class VehicleQuerySet(QuerySet):
    def vehicle_query(self, year):
      return  self.filter(common_vehicle__year__year__exact=year).exclude(status__status='Incoming')

class VehicleManager(models.Manager):
    def get_query_set(self):
      return VehicleQuerySet(self.model)

    def vehicle_query(self, year):
      return self.get_query_set().vehicle_query(year)

Then in the view:

vehicle_query = Vehicle.smart_objects.vehicle_query(year)
A: 

I think the code you have given is needlessly complicated. You don't need to define a queryset subclass, as the filtering can and should be done in the manager:

class VehicleManager(models.Manager):
    def vehicle_query(self, year):
      return self.get_query_set().filter(common_vehicle__year__year__exact=year).exclude(status__status='Incoming')

However, I don't really understand your question. You already know how to pass one variable into a manager method, why is passing additional ones any more difficult?

Daniel Roseman
managed to figure out a solution...working with sessions is a bit easier for me :) thnx for the help Daniel
Stephen