I want to retrieve the most recently added element and if there is none at all, assign some default values such as:
query = X.objects.filter(name="aa",type="b")[0]
if query:
resultname =query.name
resulttype = query.type
else:
resultname = "a default name"
resulttype = "a default type"
This is not working as it will raise an exception when the first line, query = X.objects.filter(name="aa",type="b")[0]
, executes and the filtered query list is empty.