2016-03-27 6 views
1

で見るが、いくつかの問題を抱えている...誰かが私を助けることを願って私はまだデフォルトのページ区切り機能が必要です。私の問題は、機能「get_list」であるTastypieジャンゴ、カスタム私は私のRESTインターフェイス用のカスタムエンドポイントを作成しようとしていますprepend_url

class ShareResource(ModelResource): 
    ..... 

    def prepend_urls(self): 
      return [ 
       url(r"^(?P<resource_name>%s)/dialog/(?P<account_id>\w[\w/-]*)%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('dialog'), name="api_dialog"), 
      ] 

    def dialog(self, request, **kwargs): 
      self.method_check(request, allowed=['get']) 
      self.is_authenticated(request) 

      account_id = kwargs['account_id'] 

      shares = Share.objects.filter(
       Q(account=request.user.account, post__account__id=account_id) | 
       Q(post__account=request.user.account, account=account_id) 
      ).order_by("-created") 

      raise Exception(shares) 

      return self.get_list(request, objects=shares) 

..オブジェクトに引数を取るalternativはありますか?またはカスタムビューを作成するためのより良い方法はありますか?

答えて

1

代わりobj_get_listをオーバーライドしてみてください。あなたはそれによってkwargsとフィルタオフaccount_idをポップするhttps://github.com/django-tastypie/django-tastypie/blob/master/tastypie/resources.py#L2124

勧めします。

また、ただのフィルタリングは、セキュリティ上の理由から行われた後、あなたはと呼ばれるようにauthorized_read_listが必要になります、デフォルトobj_get_list方法の結果をフィルタリングしません。