0
私はレコードを表示するためにDjangoTablesを使用しています。 AjaxをDeleteリンクで使用して、関連するSiteレコード(およびそれにリンクされているDealレコード)を削除し、テーブルページを更新する必要はありません。 「削除」にAjaxのDjango TypeErrorアクション
クリックすると、該当するレコードを削除し、私が望んでいたように、テーブルの行を消失するが、その後、私は私のコンソールでこれを取得する:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
[19/Nov/2016 03:51:56] "GET /sites/tested/sites/delete/?recordid=1 HTTP/1.1" 500 18116
良い見ていないこと。それはなぜそこにあり、どうすればそれは消え去るのですか?
静的の.jsファイル:
$(document).ready(function() {
$(".row-delete").click(function(event) {
event.preventDefault();
var recordid;
recordid = $(this).attr("data-recordid");
$.get('sites/delete/', {recordid: recordid}, function(data){
});
$(this).parent().parent().fadeOut("fast");
});
});
ビュー:
class SiteDelete(View):
model=Site
def get (self, request):
site_id = None
if request.method == 'GET':
site_id = request.GET['recordid']
DealsToDelete = Deal.objects.filter(Site=id)
DealsToDelete.delete()
DeleteSite = Site.objects.get(id=site_id)
DeleteSite.delete()
表
class TestedTable(tables.Table):
Approve = tables.TemplateColumn('<a href="{% url \"sites:approve\" id=record.id %}"</a>Approve')
Delete = tables.TemplateColumn('<a href="{% url \"sites:delete\" %}\" data-recordid = \"{{ record.id }}\" class=\"row-delete\">Delete</a>')
Name = tables.TemplateColumn('<a href="{% url \"deals:bysite\" record.id %}"</a>{{ record.Name }}')
urls.py
from django.conf.urls import url
from sites.views import SiteCreate, SiteUpdate, SiteDelete, IndexView, TestedView, DetailView, ApproveSite
from django.core.urlresolvers import reverse_lazy
app_name = 'sites'
urlpatterns = [
url(r'^$', IndexView.as_view(), name='site-list'),
url(r'add/$', SiteCreate.as_view(), name='site-add'),
url(r'(?P<pk>[0-9]+)/update/$', SiteUpdate.as_view(), name='site-update'),
url(r'delete/$', SiteDelete.as_view(), name='delete'),
url(r'tested/$', TestedView.as_view(), name='site-tested'),
url(r'(?P<pk>[0-9]+)/$', DetailView.as_view(), name='detail'),
url(r'(?P<id>[0-9]+)/approve/$', ApproveSite.as_view(), name='approve')
詳細コンソール出力:上記の行で
Internal Server Error: /sites/tested/sites/delete/
Traceback (most recent call last):
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/danny/Documents/LiClipse Workspace/AskArby/sites/views.py", line 34, in get
DealsToDelete = Deal.objects.filter(Site=id)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/query.py", line 790, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/query.py", line 808, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1243, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1269, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1199, in build_filter
condition = lookup_class(lhs, value)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/lookups.py", line 19, in __init__
self.rhs = self.get_prep_lookup()
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/fields/related_lookups.py", line 100, in get_prep_lookup
self.lookup_name, self.rhs)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 744, in get_prep_lookup
return self.get_prep_value(value)
File "/home/danny/Documents/virtualenvs/AskArbyEnv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 976, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
[19/Nov/2016 03:51:56] "GET /sites/tested/sites/delete/?recordid=1 HTTP/1.1" 500 18116
素晴らしい!ありがとうございました。 – RubyNoob