您可以將Manager的方法應用於QuerySet對象。
第一:
的.all()
末不需要在:
accounts = company_account.objects.filter(company=userinfo.company).all()
# this is the same that
accounts = company_account.objects.filter(company=userinfo.company)
二:
如果你想排除從queryset的一個對象,你可以使用:
accounts = accounts.exclude(**criteria**)
第三張:
對於你的情況,你可以用Concat(Django的1.8+)試試這個:
from django.db.models import Value, CharField
from django.db.models.functions import Concat
accounts.annotate(full_name=Concat('first_name_lower', Value(' '), 'last_name_lower'),
output_field=CharField()).exclude(full_name=something_here)
排除的問題是我需要排除基於兩個值:first_name_lower和last_name lower,因此我需要刪除典型排除之外的queryset項目。 –