1👍
✅
Use first()
instead of get()
so no exceptions will be thrown:
Manager:
class CustomerReferralManager(models.Manager):
def get_referral(self, mobile_number, campaign):
return self.objects.filter(mobile=mobile_number).first()
Method:
referral = CustomerReferral.objects.get_referral(mobile_number=mobile, campaign=campaign)
if referral:
referral.complete_referral()
Source:stackexchange.com