I am having two models and a custom Manager:
class ActiveModelAManager(models.Manager):
def get_query_set(self):
return super(ActiveModelAManager,self).get_query_set().filter( active = True)
class ModelA(models.Model):
name = CharField(....)
active = BooleanField()
active_models = ActiveModelAManager()
objects = models.Manager()
class ModelB(models.Model):
modelA = ForeignKey(ModelA)
in my view I am passing ModelA to the template and I would like to access ModelB_set but using my active_models manager instead of objects ?
so if I am doing this :
{{ ModelB.modelb_set.all }}
I am accessing the objects manager but I want to access the active_models.
Same problem goes when I am trying to access the custom manager via my view.
Any idea how can I accomplish this ?
Not sure whether I got your question right, but in order to query for the modelB objects which reference to an active ModelA object, in your view you can just write.
Related docs:
values-list
__in