It appears that not everyone knows that in python you can create classes dynamically without metaclasses. I'll show an example of how to do it.
So we've learned how to use custom QuerySet to chain requests:
Now we need to make it work for related objects:
user.articles.old().public()
This is done using use_for_related_fields, but it needs a little trick. Thing is that in django related managers are initialized without arguments, and our QuerySetManager takes argument - queryset class.
We have to update QuerySetManager in such a way, that will allow setting queryset as class field:
In order to use this manager, we have to create a sublcass and set queryset_class:
It's not fun to create such class every time. So we'll write a function that does it for us:
Now it's enough to write: