How to annotate query set with count of field in generic relation with Django ORM using Django 1.6

226 Views Asked by At
class Purchase(models.Model):
    content_type = models.ForeignKey(ContentType)
    content_uid = UUIDField(auto=False,unique=False)
    content = generic.GenericForeignKey('content_type', 'content_uid')
    user = models.ForeignKey(User)

 class Offer(models.Model):
    …
    uid = UUIDField(auto=True,unique=True,primary_key=True)
    code = models.CharField(max_length=10)
    …

I would like to have a query set which contains the count of offers with same code purchased by each user, i.e. each row will contain:

  1. a username
  2. a code
  3. number of times the same code has been used by the user
0

There are 0 best solutions below