def as_sql(self, compiler, connection):
    lhs, params = compiler.compile(self.lhs)
return 'LENGTH(%s)' % lhs, params
CharField.register_lookup(CharacterLength)
Django - Filter queryset by CharField value length