2
You can exclude()
the empty first_name values:
Friendship.objects.exclude(head_user__first_name='')
Note that if the first_name
is NULL
(not an empty string), you would need to use __isnull
:
Friendship.objects.exclude(head_user__first_name__isnull=True)
And, yeah, you can chain excludes if you do want to exclude both NULL
and empty values:
Friendship.objects.exclude(head_user__first_name__isnull=True) \
.exclude(head_user__first_name='')
Source:stackexchange.com