1 | from django.db import models
|
---|
2 |
|
---|
3 | class Animal(models.Model):
|
---|
4 |
|
---|
5 | name = models.CharField(max_length=100)
|
---|
6 |
|
---|
7 | class Meta:
|
---|
8 | abstract = False
|
---|
9 |
|
---|
10 | def say_hello(self):
|
---|
11 | pass
|
---|
12 |
|
---|
13 |
|
---|
14 | class Dog(Animal):
|
---|
15 |
|
---|
16 | def say_hello(self):
|
---|
17 | print '%s says woof' % self.name
|
---|
18 |
|
---|
19 |
|
---|
20 | class Cat(Animal):
|
---|
21 |
|
---|
22 | def say_hello(self):
|
---|
23 | print '%s says meaow' % self.name
|
---|
24 |
|
---|
25 |
|
---|
26 | __test__ = {'API_TESTS': """
|
---|
27 |
|
---|
28 | >>> dog = Dog(name='Pluto')
|
---|
29 | >>> dog.say_hello()
|
---|
30 | Pluto says woof
|
---|
31 | >>> dog.save()
|
---|
32 |
|
---|
33 | >>> cat = Cat(name='Felix')
|
---|
34 | >>> cat.say_hello()
|
---|
35 | Felix says meaow
|
---|
36 | >>> cat.save()
|
---|
37 | >>> cat.name = 'Garfield'
|
---|
38 | >>> cat.save(force_update=True)
|
---|
39 | >>> cat.say_hello()
|
---|
40 | Garfield says meaow
|
---|
41 | """}
|
---|