django exedittabledataview搜索列

问题描述 投票:1回答:1

我正在尝试对网站中的数据表进行搜索,

在models.py中,我拥有:

class Mymodel(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.TextField()
    body = models.TextField()
    creator = models.CharField(max_length=255, blank=True, db_index = True)
    creation_time = models.DateTimeField( db_index = True )
    event_id = models.CharField(unique=True, max_length=255)
    capture_rule = models.ForeignKey(CaptureRule, db_index = True)
    status = models.ForeignKey(EventStatus, null = True, blank=True, db_index = True)
    comment = models.TextField( null = True, blank = True )
    source_url = models.CharField(max_length=4096, null = True, blank = True )
    links = models.ManyToManyField( Link, related_name = 'events' )

以及在我的views.py:

class edittest(XEditableDatatableView):
model = Event
template_name = 'webapp/index.html'

datatable_options = {
    'columns':[( 'Time', 'creation_time', 'get_event_age' ),
                ( 'Status', 'status', make_xeditable( type='select' ), 'status__name' ),
                ( 'Creator', 'creator' ),
                ( 'Source', 'source' ),
                ( 'Title', 'title' ),
                ( 'Body', 'body', 'get_body_with_markup' ),
                'comment',
                'id',
                'source_url',
                ( 'Tag', 'capture_rule__tag__name' ),
                ( 'Matcher', 'capture_rule__matcher'),
                'linked_urls',
                'capture_rule'

    ],
    'search_fields': [ 'status__name' ],
    'hidden_columns' : ['body', 'comment', 'id', 'source_url', 'linked_urls', 'capture_rule' ],
    'ordering':['-creation_time'],
}

并且工作正常,但是当我将search_fields参数更改为

'search_fields': [ 'title' ] or  'search_fields': [ 'comment' ]

它搜索整列,就像我写的那样:'search_fields': []

django x-editable
1个回答
0
投票

这可能是因为搜索字段不应已经出现在列列表中。

总是在列表后附加类似过滤器的ORM字段的列表在表上执行搜索时的搜索字段数。search_fields应该只包含ORM路径,而不是已经在列定义中,因为这些已经被默认值。

https://pypi.python.org/pypi/django-datatable-view/0.5.5

© www.soinside.com 2019 - 2024. All rights reserved.