Answer the question
In order to leave comments, you need to log in
How to implement dynamic model field validation in Django?
In the model I have fields:
# платежная система, на которую персона запросила вывод средств
eps = models.ForeignKey(EPS, verbose_name='Куда')
# номер счета, на который персона запросила вывод
account = models.CharField(verbose_name="На счет", max_length=50,
validators=[RegexValidator(eps.account_PCRE, message=_('Неверный формат счета'))]
)
validators=[RegexValidator(eps.account_PCRE, message=_('Неверный формат счета'))]
AttributeError: 'ForeignKey' object has no attribute 'account_PCRE'
class WithdrawalsForm(forms.ModelForm):
class Meta:
model = Withdrawals
fields = ['eps', 'account']
widgets = {
'account': forms.TextInput(attrs={'class': 'inputboxsmall', 'data-inputmask': ''})
}
Answer the question
In order to leave comments, you need to log in
You can raise the desired ValidationError in the clean method in the model itself:
https://docs.djangoproject.com/en/1.6/ref/models/i...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question