其他分享
首页 > 其他分享> > Django filter operators

Django filter operators

作者:互联网

operators = {
        'exact': '= %s',
        'iexact': 'LIKE %s',
        'contains': 'LIKE BINARY %s',
        'icontains': 'LIKE %s',
        'regex': 'REGEXP BINARY %s',
        'iregex': 'REGEXP %s',
        'gt': '> %s',
        'gte': '>= %s',
        'lt': '< %s',
        'lte': '<= %s',
        'startswith': 'LIKE BINARY %s',
        'endswith': 'LIKE BINARY %s',
        'istartswith': 'LIKE %s',
        'iendswith': 'LIKE %s',
    }
# example
data = M.objects.filter(field1__gt=0).filter(field2__icontains='abc')
data = M.objects.filter(Q(field1__icontains='abc') & Q(field2__icontains='def') | Q(field3__icontains='ghi'))

标签:regex,BINARY,LIKE,operators,iexact,Django,filter,REGEXP
来源: https://www.cnblogs.com/congxinglong/p/16425692.html