A.J.
A.J.

Reputation: 8985

Django ORM get by ID - do I need to convert Id to Int?

Do I need to convert this_object_id to int before I can pass to id?

obj = Class.objects.get(id=this_object_id)

Why or why not?

Upvotes: 1

Views: 217

Answers (1)

devinformatics
devinformatics

Reputation: 72

Accepts both. Ultimately you are building an SQL query statement, so passing an int that gets converted to a string or a string that gets inserted both work. See http://django.readthedocs.org/en/latest/ref/models/lookups.html#lookup-reference for the lhs and rhs sides of the clause that is being constructed.

Upvotes: 1

Related Questions