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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -