为什么会出现错误?
如果在form.save()
出现之后调用任何if块,那么' int' object不是可迭代的错误
以下代码:
if request.method =='POST':
if form.is_valid():
form.instance.user = request.user
is_auction = request.POST.get("create_auction", "")
phone_number = request.POST.get("phone", "")
attr_dic = {}
for attr in form.cleaned_data['subcategory'].attributes.all().order_by('ordering'):
if request.POST.get(attr.name):
attr_desc={}
attr_desc['verbos_name'] = attr.verbos_name
if attr.attr_type =='choice':
attr_desc['value'] = str(attr.dict.model_class().objects.get(pk=request.POST.get(attr.name)).pk)
# attr_desc['value'] = str(attr.attributevalue_set.get(pk=request.POST.get(attr.name)).pk)
attr_desc['value_name'] = str(attr.dict.model_class().objects.get(pk=request.POST.get(attr.name)).name)
# attr_desc['value_name'] = attr.attributevalue_set.get(pk=request.POST.get(attr.name)).vallue
else:
attr_desc['value'] = request.POST.get(attr.name)
attr_desc['value_name'] = request.POST.get(attr.name)
attr_desc['ordering'] = attr.ordering
attr_desc['filtering'] = attr.filtering
attr_dic[attr.name] = attr_desc
form.instance.attributes = attr_dic
form.save()
if region is None:
p, updated = request.user.userprofiletable_set.update(adress_state= form.cleaned_data['state'] ,adress_city =form.cleaned_data['city'] )
if (contact_phone == '' or contact_phone !=phone_number):
p, updated = request.user.userprofiletable_set.update(phone=phone_number)
if is_auction=='on':
p, created =Auction.objects.get_or_create(product=form.instance,title=form.instance.name,description=request.POST.get("description_auct", ""),
start_price=request.POST.get("start_price", ""),
end_price=request.POST.get("end_price", ""),
min_price_step=request.POST.get("min_price_step", ""),
end_date=request.POST.get("end_date", ""),
currency=form.instance.currency)
return redirect(url)
微量
TypeError at /callboard/createadv/
'int' object is not iterable
Request Method: POST
Request URL: http://127.0.0.1:8000/callboard/createadv/?next=/
Django Version: 1.10.5
Exception Type: TypeError
Exception Value:
'int' object is not iterable
Exception Location: /Users/korablevop/PycharmProjects/naxodu/callboard/views.py in createadv, line 259
Python Executable: /Users/korablevop/.virtualenvs/mynewenv/bin/python