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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -