I have being playing with this for hours with out find a solution.
I have the following models:
class Category(models.Model):
name = models.CharField(max_length=100)
class Item(models.Model):
name = models.CharField(max_length=250)
category = models.ForeignKey(Category)
Then I filter the Items and the categories related to that item:
items = Item.objects.filter(name=name)
categories = Category.filter(id__in = items.values_list('category__id'))
Now I want to get the number of the items with a category and save that number in a field in categories with annotate
How can I do it?