[Answered ]-Django model constraint for ensuring one or both fields are not empty strings

1👍

You can use ~ as the NOT operator:

check = (
    Q(Q(firstname__exact="") & ~Q(surname__exact="")) | 
    Q(~Q(firstname__exact="") & Q(surname__exact="")) | 
    Q(~Q(firstname__exact="") & ~Q(surname__exact=""))
)

Leave a comment