1 | from django import test
|
---|
2 | from django.db import models
|
---|
3 |
|
---|
4 | class Person(models.Model):
|
---|
5 | name = models.CharField(max_length=50)
|
---|
6 |
|
---|
7 | class Politician(models.Model):
|
---|
8 | politician_id = models.AutoField(primary_key=True)
|
---|
9 | title = models.CharField(max_length=50)
|
---|
10 |
|
---|
11 | class Congressman(Person, Politician):
|
---|
12 | state = models.CharField(max_length=2)
|
---|
13 |
|
---|
14 | class Senator(Congressman):
|
---|
15 | pass
|
---|
16 |
|
---|
17 | class MultiInheritanceTest(test.TestCase):
|
---|
18 | def test_multiple_inheritance(self):
|
---|
19 | Politician.objects.create(title='Ms.')
|
---|
20 | Person.objects.create(name="A")
|
---|
21 | Person.objects.create(name="B")
|
---|
22 | Person.objects.create(name="C")
|
---|
23 |
|
---|
24 | senator = Senator.objects.create(name='John Doe',
|
---|
25 | title='Maj. Leader',
|
---|
26 | state='TX')
|
---|
27 |
|
---|
28 | #print Senator.objects.filter(politician_id=1).query
|
---|
29 |
|
---|
30 | senator_copy = Senator.objects.get(politician_id=senator.politician_id)
|
---|
31 |
|
---|
32 | self.assertEqual(senator.pk, senator_copy.pk)
|
---|