class AuthorCls(SelectFilterCls): MODEL = Author FILTERS = ( { 'namespace': 'publisher', 'qs': NSR('publisher'), 'filters': ( { 'namespace': 'fk', 'source': 'fk1', 'qs': NSR('fk1'), 'filters': ('id', ), }, { 'namespace': 'fk2', 'source': 'fk2', 'qs': NSR('fk2'), 'filters': ('id', ), }, { 'namespace': 'authors', 'qs': NPR('authors'), 'filters': ('id', ), }, ), }, { 'namespace': 'fk1', 'qs': NSR('fk'), 'filters': ('id', ), }, { 'filter': 'id', 'qs': NPR('books'), }, )
class Cls(SelectFilterCls): FILTERS = ( { 'filter': 'ns.author', 'dynamic': True, 'qs': NSR('author'), 'field': SelectField(), }, { 'namespace': 'ns2', 'source': 'author', 'qs': AN(ns=Value('abc', CharField(max_length=128))), 'filters': ('id', ), }, )
class Cls(SelectFilterCls): FILTERS = ( 'id', { 'filter': 'ft1', 'source': 'id', 'qs': SR('author'), }, { 'filter': 'ft2', 'source': 'id', 'qs': NSR('author'), }, { 'namespace': 'ns', 'source': 'author', 'qs': NPR('author', 'pages'), 'filters': ( { 'filter': 'ft1', 'source': 'id', 'qs': SR('author__publisher'), }, { 'filter': 'ft2', 'source': 'id', 'qs': NSR('publisher'), }, { 'namespace': 'ns', 'source': 'publisher', 'qs': NPR('publisher'), 'filters': ({ 'filter': 'id', 'qs': AN(abc=Value(1, IntegerField())), }, ), }, ), }, { 'namespace': 'pages', 'qs': PR('pages'), 'filters': ({ 'namespace': 'book', 'filters': ({ 'filter': 'author', 'source': 'author__id', 'qs': CH(NSR('author'), NSR('author__publisher')), }, ), }, ), }, )
def test_nested_chain_parent(): qs = NSR('publisher').rebuild(Chain(Chain(NSR('author'), NPR('pages')))).apply(default_qs) assert qs.query.select_related == {'author': {'publisher': {}}}
def test_nested_deep_nesting(): qs = NPR('authors').rebuild(NSR('publisher').rebuild(NSR('author'))).apply(default_qs) assert qs._prefetch_related_lookups == ('author__publisher__authors',)
def test_chain_parent_pr(): qs = Chain(NSR('publisher')).rebuild(Chain(PrefetchRelated('author'))).apply(default_qs) assert qs._prefetch_related_lookups == ('author__publisher',)
def test_chain_parent_sr(): qs = Chain(NSR('publisher')).rebuild(Chain(SelectRelated('author'))).apply(default_qs) assert qs.query.select_related == {'author': {'publisher': {}}}
from django.db.models import AutoField, CharField, F, IntegerField from py_rql.constants import FilterLookups, RQL_NULL from tests.dj_rf.models import Book AUTHOR_FILTERS = [ 'is_male', { 'filter': 'email', 'ordering': True, 'search': True, }, { 'namespace': 'publisher', 'filters': ['id'], 'distinct': False, 'qs': NSR('publisher'), } ] PAGE_FILTERS = [{ 'filter': 'number', 'lookups': {FilterLookups.EQ, FilterLookups.NE}, }, { 'filter': 'id', 'source': 'uuid', }] class BooksFilterClass(RQLFilterClass): MODEL = Book QUERIES_CACHE_BACKEND = LFUCache