Concatenate two string and one integer

Hello everyone,

How can I add two sting and one integer value in django views? Below code gives me this error: unsupported operand type(s) for +: ‘QuerySet’ and ‘str’

pid_check = request.POST.get('select_project')
p = Projects.objects.filter(id=pid_check).values('prefix')
index = Samples.objects.count()
sid_check = request.POST.get('select_sourcesample')
s = SourceSamples.objects.filter(id=sid_check).values('suffix')
sample.p_id_s = p +  str(index+1) + s

Thank you in advance.

I think, the problem is what filters return.


They do not return parameter as string.

If I implement sample.p_id_s = “{}{}{}”.format(p[0], index+1, s[0])
I get result:
{‘prefix’: ‘V’}13{‘suffix’: ‘S’}

But I only want to print it in the table as V13S.

Do you have any idea how to fix that problem?


So what is the data type you are getting?

Review the docs at Making queries | Django documentation | Django and QuerySet API reference | Django documentation | Django to better understand what those functions are doing.

I would suggest experiementing with the Django shell to get used to working with querysets and what they return. See Writing your first Django app, part 2 | Django documentation | Django for an example.

1 Like