django orm, custom method on top of a queryset
lets suppose that some code in my view looks like this:
bar = Bar.objects.get(pk=1)
foos = bar.foo_set.filter(VERY_LONG_COMPLEX_FILTERING_LOGIC)
I would obviously want to clean the filter method a bit, by creating a custom method that does the same thing, like so:
bar = Bar.objects.get(pk=1)
foos = bar.foo_set.complexfilter()
Moving the custom method somewhere to a class would be perfect, but so far I couldn't find any mention 开发者_C百科of anything like that in the docs. Any suggestions?
Thank you in advance.
Placing it in bar
's method seems good.
精彩评论