私の BackboneJS モデルは、メソッドを呼び出すGET
代わりに を送信するようになりました。REST API用のdjango-tastypieを使用したDjangoバックエンドがあります。PUT
model.save()
たとえば、次のように更新しようとするユーザー モデルがあります。
var me = new UserModel({
id: this.user.id
});
me.fetch({
success: function (t) {
console.log(t);
t.set({
'premium': true
});
t.save({
success: function () {
alert('success')
},
error: function (m, e) {
console.log(e);
}
});
}
})
コンソールに次のエラーが表示されます。
GET http://127.0.0.1:8000/api/v1/users/100003258103084/ 500 (INTERNAL SERVER ERROR)
私が持っている行でt.save()
ここで私が間違っていることはありますか?
編集
さて、行に表示されるメッセージconsole.log(e)
は次のとおりです。
"{"error_message": "int() argument must be a string or a number, not 'dict'", "traceback": "Traceback (most recent call last):\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 192, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 406, in dispatch_detail\n return self.dispatch('detail', request, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 427, in dispatch\n response = method(request, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1131, in put_detail\n updated_bundle = self.obj_update(bundle, request=request, **self.remove_api_resource_names(kwargs))\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1827, in obj_update\n m2m_bundle = self.hydrate_m2m(bundle)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 743, in hydrate_m2m\n bundle.data[field_name] = field_object.hydrate_m2m(bundle)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/fields.py\", line 742, in hydrate_m2m\n m2m_hydrated.append(self.build_related_resource(value, **kwargs))\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/fields.py\", line 593, in build_related_resource\n return self.resource_from_data(self.fk_resource, value, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/fields.py\", line 548, in resource_from_data\n return fk_resource.obj_update(fk_bundle, **data)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1814, in obj_update\n bundle.obj = self.obj_get(request, **lookup_kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1752, in obj_get\n base_object_list = self.get_object_list(request).filter(**kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/query.py\", line 621, in filter\n return self._filter_or_exclude(False, *args, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/query.py\", line 639, in _filter_or_exclude\n clone.query.add_q(Q(*args, **kwargs))\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py\", line 1250, in add_q\n can_reuse=used_aliases, force_having=force_having)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py\", line 1185, in add_filter\n connector)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/sql/where.py\", line 69, in add\n value = obj.prepare(lookup_type, value)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/sql/where.py\", line 320, in prepare\n return self.field.get_prep_lookup(lookup_type, value)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/fields/related.py\", line 137, in get_prep_lookup\n return self._pk_trace(value, 'get_prep_lookup', lookup_type)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/fields/related.py\", line 210, in _pk_trace\n v = getattr(field, prep_func)(lookup_type, v, **kwargs)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 310, in get_prep_lookup\n return self.get_prep_value(value)\n\n File \"/home/mohamed/code/skempi/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 537, in get_prep_value\n return int(value)\n\nTypeError: int() argument must be a string or a number, not 'dict'\n"}"
これは、BackbonejS ではなく Django-Tastypie に問題があるということですか? それでもこれGET
は私が推測する問題です!