2014-01-15 52 views
0

我正在測試django-tables2-simplefilter。 我需要更好地理解內部運作。 從文檔,有關定義過濾器:django-tables2-simplefilter工作示例

「添加過濾選項SingleTableView在表 子類(不Table.Meta)可能不會保證定義的過濾器列表」

我已經有我的工作表,使用領域和元訂購E選擇列

class CouponTable(tables.Table): 
     coupon = tables.Column(verbose_name="Coupon") 
     description = tables.Column(accessor="coupon.description", verbose_name="Descrizione") 
     activationDate = tables.DateColumn(verbose_name="Data di attivazione") 
     useDate = tables.DateColumn(verbose_name="Data di utilizzo") 
     sel =tables.CheckBoxColumn(accessor="pk", orderable=False) 

     class Meta: 
       model = yieldCoupons 
       sequence= ("sel", "coupon", "description", "activationDate", "useDate") 
       fields = ("sel", "coupon", "description", "activationDate", "useDate") 

的第一個問題是:1。 哪裏應該定義過濾器?

查看django-tables2-simplefilter的代碼,我看到了一個模板和一個css。 我想我應該包括該模板,在我的模板中顯示可用的過濾器。

這是正確的嗎?

在此先感謝

回答

0
class CouponTable(tables.Table): 

    coupon = tables.Column(verbose_name="Coupon") 
    description = tables.Column(accessor="coupon.description", verbose_name="Descrizione") 
    activationDate = tables.DateColumn(verbose_name="Data di attivazione") 
    useDate = tables.DateColumn(verbose_name="Data di utilizzo") 
    sel =tables.CheckBoxColumn(accessor="pk", orderable=False) 
    filters = your_filters 
    class Meta: 
      model = yieldCoupons 
      sequence= ("sel", "coupon", "description", "activationDate", "useDate") 
      fields = ("sel", "coupon", "description", "activationDate", "useDate") 

編輯: 函數F可以導入爲

from django_tables2_simplefilter import F 
+0

多了一個問題:在F函數定義過濾器,似乎沒有用,但我知道我已經正確安裝了django-tables2-simplefilter。我需要導入一些特定的東西嗎? – user1696626

+0

from django_tables2_simplefilter import F – praveen

+0

同樣,我從第42行的django_tables2_simplefilter/views.py(字符串索引必須是整數,而不是str)中得到TypeError。該行的代碼表示field = f ['field']無法理解。 @praveen – user1696626