我一直在寻找与我目前面临的相同问题的帖子。但我还没有找到解决办法。我的问题是:
我有一个标签列表。由 生成{% for tag in all_tags %}
。每个标签都有一个标签状态表单。当用户从下拉列表中选择一个选项时,表单提交并应该保存 TagStatus 对象(标签是外键到 TagStatus)。但是,返回的是:
Exception Type: TypeError
Exception Value: 'QueryDict' object is not callable
html:
<form class="nice" id="status-form" method="POST" action="">
{% csrf_token %}
<input type="hidden" name="status_check" />
<input type='hidden' name="tag" value="{{ tag }}" />
<select name="select" id="positionSelect" class="input-text category" onchange="this.form.submit()">
<option name="all" value="0">Your Status</option>
<option name="investing" value="1">Status 1</option>
<option name="selling" value="2">Status 2</option>
<option name="interested" value="3">Status 3</option>
</select>
</form>
视图.py:
@login_required
def tags(request):
all_tags = Tag.objects.all()
context = base_context(request)
if request.method == 'POST':
if 'status_check' in request.POST:
status = request.GET('status')
tag = request.GET('tag')
user = request.user
tag_status, created = TagStatus.objects.get_or_create(status=len(status), tag=tag, user=user).save()
response = simplejson.dumps({"status": "Successfully changed status"})
else:
response = simplejson.dumps({"status": "Error"})
return HttpResponse (response, mimetype='application/json')
context['all_tags'] = all_tags
return render_to_response('tags/tag.html', context, context_instance=RequestContext(request))
models.py(如果相关):
class TagStatus(models.Model):
user = models.ForeignKey(User, null=True, unique=True)
status = models.CharField(max_length=2, choices=tag_statuses)
tag = models.ForeignKey(Tag, null=True, blank=True)
def __unicode__(self):
return self.status
def save(self, *args, **kwargs):
super(TagStatus, self).save(*args, **kwargs)
据我所知,这与状态不是数字有关。但是当我将其转换为 int 时。我犯了同样的错误。请帮我。为什么会这样?解决方法是什么?我不太确定如何解决这个问题。提前谢谢你的帮助。