django - Using a custom reverse manager in Filter -
given have:
class publisher(model): pass class author(model): name = models.charfield(...) publisher = models.foreignkey(publisher) is_alive = models.booleanfield(...) objects = models.manager() # default manager alives = alivemanager() # custom manager
right can filter using:
publisher.objects.filter(author__name='xxx', author__is_alive=true)
my question there anyway take advantage of custom reverse manager in filter statement?
publisher.author_set(manager="alives")
gives me given publisher.
i guess relevant bit in docs:
[...] default filtering in get_queryset() method, filtering apply all() call.
class alivemanager(manager): def get_queryset(self): qs = super(alivemanager, self).get_queryset() return qs.filter(is_alive=true) class author(model): name = models.charfield(...) publisher = models.foreignkey(publisher) is_alive = models.booleanfield(...) objects = models.manager() # default manager alives = alivemanager() # custom manager # returns alive authors publisher.author_set(manager='alives').all() # filters through alive authors publisher.author_set(manager='alives').filter(author__name='xxx')
Comments
Post a Comment