Using django, which is the “way” to check if data is present?
I know i can either have a try/catch block on a get, or check the size of a len on a filter
ie
try:
DemoModel.objects.get(id=8)
catch DoesNotExist:
catch stuff here
or
if not len(DemoModel.objects.filter(id=8):
do stuff here
i suppose i’m defining “best” as
a. the standard way
b. the more efficient way
or is there no real difference? Or is there a non-partisan third way?
If you need to use the object, use try/catch.
If you don’t need to, just use exists().