Modelesq
Modelesq

Reputation: 5402

Django TypeError 'QueryDict' object is not callable

I've looked for posts that have endured the same problem that I'm currently facing. But I haven't found a solution. What my problem is:

I have a list of tags. Generated by {% for tag in all_tags %}. Each tag has a tagstatus form. When a user selects an option from a drop down, the form submits and is supposed to save the TagStatus object (Tags are foreignKey'd to TagStatus). However, what returns is this:

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>

views.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 (if its relevant):

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)

From what I gather it has something to do with the status not being a number. But when I convert it to a int. I get the same error. Please help me. Why is this happening? And whats the fix? I'm not quite sure how to solve this problem. Thank you for your help in advance.

Upvotes: 7

Views: 50259

Answers (4)

preetham-p-m
preetham-p-m

Reputation: 91

status = request.GET.get['status']

tag = request.GET.get['tag']

Upvotes: 0

Mukund Biradar
Mukund Biradar

Reputation: 151

def add(request):
    var1 = int(request.GET.get("num1"))
    var2 = int(request.GET.get("num2"))

    res= var1+var2
    return render(request,'calc/result.html',{'Result':res})

Upvotes: 1

f-re
f-re

Reputation: 71

or just call GETs get to get your values

status = request.GET.get('status')
tag = request.GET.get('tag')

Upvotes: 7

Jeffrey Froman
Jeffrey Froman

Reputation: 6623

I believe the error you're encountering is in these lines:

status = request.GET('status')
tag = request.GET('tag')

request.GET is a QueryDict, and adding () after it attempts to "call" a non-callable object. It appears the syntax you're looking for is dictionary lookup syntax instead:

status = request.GET['status']
tag = request.GET['tag']

Upvotes: 49

Related Questions