python - Speeding up django .exists() -


i have query translationstep.objects.filter(step_id=pk). need check if object exist or not , if so, return object (or several objects). have read .exists() more fastest way it, should make 2 requests.

if translationstep.objects.filter(step_id=pk).exists():  return translationstep.objects.filter(step_id=pk) else:  return none 

how can optimise it?

you shouldn't @ all. filter() return empty queryset if there no match, false in boolean context.


Comments

Popular posts from this blog

python - Best design pattern for collection of objects -

go - serving up pdfs using golang -

python - django admin: changing the way a field (w/ relationship to another model) is submitted on a form so that it can be submitted multiple times -