Ticket #10045: models.py

File models.py, 709 bytes (added by alex@…, 11 years ago)
Line 
1from django.db import models
2
3class ModelA(models.Model):
4    name = models.CharField(max_length=100)
5
6    def __unicode__(self):
7        return self.name
8
9class ModelB(models.Model):
10    name = models.CharField(max_length=100)
11    somebool = models.BooleanField(default=True)
12    a = models.ForeignKey(ModelA)
13
14    def __unicode__(self):
15        return self.name
16
17from django.db.models.aggregates import Count
18__test__ = {"doctest": """
19>>> a = ModelA.objects.create(name="testA")
20>>> b1 = ModelB.objects.create(name="B1", a=a, somebool=True)
21>>> b2 = ModelB.objects.create(name="B2", a=a, somebool=True)
22>>> ModelA.objects.all().annotate(num_b=Count('modelb')).filter(modelb__somebool=True)[0].num_b
232
24"""}
Back to Top