1 | from django.db import models
|
---|
2 |
|
---|
3 | class Employee(models.Model):
|
---|
4 | name = models.CharField(max_length=100)
|
---|
5 | salary = models.IntegerField()
|
---|
6 | birth_date = models.DateField()
|
---|
7 |
|
---|
8 | __test__ = {'API_TEST': '''
|
---|
9 | >>> from datetime import date
|
---|
10 | >>> from django.db.models import F
|
---|
11 | >>> a = Employee(name='Alex', salary=130, birth_date=date(1980, 1, 8))
|
---|
12 | >>> a.save()
|
---|
13 | >>> b = Employee(name='Brian', salary=150, birth_date=date(1970, 3, 4))
|
---|
14 | >>> b.save()
|
---|
15 | >>> c = Employee(name='Michael', salary=100, birth_date=date(1960, 5, 6))
|
---|
16 | >>> c.save()
|
---|
17 | >>> Employee.objects.all().update(salary=F('salary')+20)
|
---|
18 | >>> print Employee.objects.get(pk=a.pk).salary
|
---|
19 | 150
|
---|
20 | >>> print Employee.objects.get(pk=b.pk).salary
|
---|
21 | 170
|
---|
22 | >>> Employee.objects.all(salary=F('salary')*1.1)
|
---|
23 | >>> print Employee.objects.get(pk=a.pk).salary
|
---|
24 | 165
|
---|
25 | >>> print Employee.objects.get(pk=b.pk).salary
|
---|
26 | 187
|
---|
27 | >>> Employee.objects.filter(salary__gt=170).update(name=F('salary'))
|
---|
28 | >>> print Employee.objects.get(pk=b.pk).name
|
---|
29 | 187
|
---|
30 | '''
|
---|
31 | }
|
---|