You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

15 lines
489 B

from django.core.exceptions import ValidationError
from django.forms import ModelForm
from .models import OdpovedUcastnika, SpravnaOdpoved
class SifrovackaForm(ModelForm):
class Meta:
model = OdpovedUcastnika
fields = ["sifra", "odpoved", ]
def clean_sifra(self):
sifra = self.cleaned_data.get('sifra')
if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0:
raise ValidationError("Tohle číslo šifry v databázi nemáme. Zkontrolujte si ho prosím.")
return sifra