django - Exclude issue to get the count with a subquery -


i have 2 models.

item

class item:    name = charfield  class itemcopy:    orig = foreignkey(item)    copy = foregin key (item) 

so want count of items want exclude if item id existing in itemcopy.copy. item has no connection itemcopy itemcopy has connection item.

maybe this:

item.objects.exclude(itemcopy=item.id).count() 

anyone has idea how can exclude it?

thanks

i solved on way subquery.

item.objects.exclude(id__in=itemcopy.objects.values_list("copy", flat=true)).count() 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -