I have an interface including an inputText and submit button, I would like to test (forms.py) if the value entered already exists in the data base when I click to save the key entered in the textField. I am still new on Python, thank you for your help.
def save(self, commit=True):
# validate if legacy key exist
key_value = self.data.get('key_id')
try:
key_request = self.key_id.filter(key_value=self.key)
if key_request.exists():
raise Exception(_("key already exists"))
except Academic.DoesNotExist:
pass
Aucun commentaire:
Enregistrer un commentaire