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

angular - Converting AngularJS deffered promise to AngularX observable for JSOM -

python - What's the Pythonic way to report nonfatal errors in a parser? -

python - AssertionError when trying to assert return value from two dictionaries with py.test -