CheckResourceとの関係として、以下の「支払い」フィールドを追加しました。
class CheckResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user', full=True)
venue = fields.ForeignKey(VenueResource, 'venue', full=False)
payments = fields.ToManyField('payments.api.PaymentResource',
attribute=lambda bundle: Payment.objects.filter(check=bundle.obj),
related_name=check,
full=True,
null=True,
blank=True
)
list / getですべてがうまく機能しますが、作成しようとすると、次のエラーが発生します。
{"error_message": "getattr(): attribute name must be string", "traceback": "Traceback (most recent call last):\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 192, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 397, in dispatch_list\n return self.dispatch('list', request, **kwargs)\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 427, in dispatch\n response = method(request, **kwargs)\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 1165, in post_list\n updated_bundle = self.obj_create(bundle, request=request, **self.remove_api_resource_names(kwargs))\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 1784, in obj_create\n self.save_m2m(m2m_bundle)\n\n File \"/Library/Python/2.7/site-packages/tastypie/resources.py\", line 1942, in save_m2m\n related_mngr = getattr(bundle.obj, field_object.attribute)\n\nTypeError: getattr(): attribute name must be string\n"}
どんな手掛かり?
ありがとう!マーク
更新:私のPaymentResourceは次のようになります:
class PaymentResource(ModelResource):
from checks.api import CheckResource
venue = fields.ForeignKey(VenueResource, 'venue', full=False)
check = fields.ToOneField(CheckResource, 'check', full=False)
user = fields.ForeignKey(UserResource, 'user', full=False)