diff --git a/tests/expressions/models.py b/tests/expressions/models.py
index 69de52c..1c1e924 100644
a
|
b
|
from django.utils.encoding import python_2_unicode_compatible
|
12 | 12 | class Employee(models.Model): |
13 | 13 | firstname = models.CharField(max_length=50) |
14 | 14 | lastname = models.CharField(max_length=50) |
| 15 | salary = models.IntegerField(blank=True, null=True) |
15 | 16 | |
16 | 17 | def __str__(self): |
17 | 18 | return '%s %s' % (self.firstname, self.lastname) |
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 7233fa0..e3073a4 100644
a
|
b
|
import uuid
|
5 | 5 | from copy import deepcopy |
6 | 6 | |
7 | 7 | from django.core.exceptions import FieldError |
8 | | from django.db import DatabaseError, connection, transaction |
| 8 | from django.db import DatabaseError, connection, models, transaction |
9 | 9 | from django.db.models import TimeField, UUIDField |
10 | 10 | from django.db.models.aggregates import ( |
11 | 11 | Avg, Count, Max, Min, StdDev, Sum, Variance, |
… |
… |
class BasicExpressionsTests(TestCase):
|
30 | 30 | def setUpTestData(cls): |
31 | 31 | Company.objects.create( |
32 | 32 | name="Example Inc.", num_employees=2300, num_chairs=5, |
33 | | ceo=Employee.objects.create(firstname="Joe", lastname="Smith") |
| 33 | ceo=Employee.objects.create(firstname="Joe", lastname="Smith", salary=10) |
34 | 34 | ) |
35 | 35 | Company.objects.create( |
36 | 36 | name="Foobar Ltd.", num_employees=3, num_chairs=4, |
37 | | ceo=Employee.objects.create(firstname="Frank", lastname="Meyer") |
| 37 | ceo=Employee.objects.create(firstname="Frank", lastname="Meyer", salary=20) |
38 | 38 | ) |
39 | 39 | Company.objects.create( |
40 | 40 | name="Test GmbH", num_employees=32, num_chairs=1, |
41 | | ceo=Employee.objects.create(firstname="Max", lastname="Mustermann") |
| 41 | ceo=Employee.objects.create(firstname="Max", lastname="Mustermann", salary=30) |
42 | 42 | ) |
43 | 43 | |
44 | 44 | def setUp(self): |
… |
… |
class BasicExpressionsTests(TestCase):
|
48 | 48 | "name", "num_employees", "num_chairs" |
49 | 49 | ) |
50 | 50 | |
| 51 | def test_annotate_values_aggregate(self): |
| 52 | companies = Company.objects.annotate( |
| 53 | salaries=F('ceo__salary'), |
| 54 | ).values('num_employees', 'salaries').aggregate( |
| 55 | result=Sum(F('salaries') + F('num_employees'), |
| 56 | output_field=models.IntegerField()), |
| 57 | ) |
| 58 | self.assertEqual(companies['result'], 60) # 2395 without values |
| 59 | |
51 | 60 | def test_filter_inter_attribute(self): |
52 | 61 | # We can filter on attribute relationships on same model obj, e.g. |
53 | 62 | # find companies where the number of employees is greater |