Hi,
Great to hear you solved your issue. One thing that I think is nice to know, and it sure has helped me along the way, is using the DoesNotExist
exception to your advantage which can simplify this code and reduce the the number of queries to one.
try:
currency = UserPreference.objects.get(user = request.user).currency
except UserPreference.DoesNotExist:
currency = 'INR - Indian Rupee'
In short, the try except clause tries to get(user=request.user)
an object matching your query. If there is no matching result it will raise the DoesNotExist
exception and the except
will catch it, executing the line of code after the except clause.