2
在脫水過程中,我創建一個自定義值:如何篩選脫水期間創建的自定義值?
def dehydrate(self, bundle):
bundle.data['custom_field'] = ["add lots of stuff and return an int"]
return bundle
,我想過濾的。
/?format=json&custom_field__gt=0...
但是我得到了"[custom_field] field has no 'attribute' for searching with."
也許我誤解自定義過濾器的錯誤,但在這兩種build_filters
和apply_filters
我似乎無法獲得訪問我的自定義字段上進行篩選。在我見過的例子中,似乎我不得不重做所有在build_filters中脫水完成的工作,例如
for all the items:
item['custom_field'] = ["add lots of stuff and return an int"]
filter on item and add to pk_list
orm_filters["pk__in"] = [i.pk for i in pk_list]
這似乎是錯誤的,因爲我在做兩次工作。我錯過了什麼?