残念ながらありません。
問題は、TastypieのModelResourceクラスがQuerySetのfilter()メソッドのみを使用することです。つまり、負のフィルターに使用する必要があるexclude()を使用しません。ただし、否定を意味するfilter()フィールドルックアップはありません。有効なルックアップは次のとおりです(このSO投稿の後):
exact
iexact
contains
icontains
in
gt
gte
lt
lte
startswith
istartswith
endswith
iendswith
range
year
month
day
week_day
isnull
search
regex
iregex
ただし、「__not_eq」のようなサポートを実装するのはそれほど難しいことではありません。あなたがする必要があるのは、apply_filters()メソッドを変更し、「__not_eq」でフィルターを残りから分離することです。次に、最初のグループをexclude()に渡し、残りをfilter()に渡す必要があります。
何かのようなもの:
def apply_filters(self, request, applicable_filters):
"""
An ORM-specific implementation of ``apply_filters``.
The default simply applies the ``applicable_filters`` as ``**kwargs``,
but should make it possible to do more advanced things.
"""
positive_filters = {}
negative_filters = {}
for lookup in applicable_filters.keys():
if lookup.endswith( '__not_eq' ):
negative_filters[ lookup ] = applicable_filters[ lookup ]
else:
positive_filters[ lookup ] = applicable_filters[ lookup ]
return self.get_object_list(request).filter(**positive_filters).exclude(**negative_filters)
デフォルトの代わりに:
def apply_filters(self, request, applicable_filters):
"""
An ORM-specific implementation of ``apply_filters``.
The default simply applies the ``applicable_filters`` as ``**kwargs``,
but should make it possible to do more advanced things.
"""
return self.get_object_list(request).filter(**applicable_filters)
次の構文を考慮に入れる必要があります。
someapi.com/resource/pk/?field__not_eq=value
私はそれをテストしていません。おそらくもっとエレガントな方法で書くこともできますが、うまくいくはずです:)