Django not like statement

2019-06-24 04:58发布

问题:

how to use not like in django queries

    Model.objects.filter(keywords not like "null" or "undefined")

       select * from model where keywords not like "%undefined%"  or keywords not like "%null%";

回答1:

use the exclude function and Q objects

Model.objects.exclude(Q(keyword__contains='undefined') | Q(keyword__contains='null'))