Answer the question
In order to leave comments, you need to log in
How to make mandatory one of two fields in Django model?
Such a question in general,
There is a model:
Phone(Model):
iphone = charfield...bla-bla-bla
android = charfield bla bla bla
Answer the question
In order to leave comments, you need to log in
1. In the model - blank=True for both fields
2. In forms.py you make a class based on the model. Actually, both fields will be available for you to fill in, and both of them can also be empty.
2.1. In the class, you create a method a la clean() , in which you clear these fields from nasty things, and then you do a type check:
if not iphone and not android:
raise ValidationError("Укажи хоть что-то")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question