【发布时间】:2012-02-06 01:32:39
【问题描述】:
我尝试使用此段过滤并获取一组对象。
baseSet = ThreadedComment.objects.filter(tree_path__contains = baseT.comment_ptr_id)
但它带来了一些不应该存在的对象。 比如我的baseT.comment_ptr_id是1,它带了这些tree_path的项目。
comment_ptr_id=1 treepath = 0000000001
comment_ptr_id=3 treepath = 0000000001/0000000003
comment_ptr_id=4 treepath = 0000000001/0000000003/0000000004
comment_ptr_id=8 treepath = 0000000001/0000000003/0000000004/0000000008
comment_ptr_id=10 treepath = 0000000006/0000000010
comment_ptr_id=11 treepath = 0000000011
最后两个不应该在这里。但由于他们的 tree_path 包含“1” 过滤器也会带来这些。
如何编写正则表达式来创建不带这些项目的过滤器?
【问题讨论】: