1👍
✅
You also have to catch the DoesNotExist
error. Change the if query
to a try except block:
try:
result = CertificateHolder.objects.get(cert_no=query)
except DoesNotExist:
pass
3👍
You have to use the Django validation and try to access the database from the ‘clean’ method the way @ilse2005 referred to . if you got DoesNotExist exception you have to raise an error in the form itself and handle it in your template.
- [Django]-Django ModelChoiceField using distinct values from one model attribute
- [Django]-How to get a property from a Django model?
- [Django]-How to implement Northwind in Django
- [Django]-Installing a Module on Heroku
- [Django]-Add Property to Django Result Object
Source:stackexchange.com