Ticket #10967: models.py

File models.py, 656 bytes (added by Lorenzo Gil Sanchez, 16 years ago)

Simple models that show this problem

Line 
1from django.db import models
2
3class 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
14class Dog(Animal):
15
16 def say_hello(self):
17 print '%s says woof' % self.name
18
19
20class 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()
30Pluto says woof
31>>> dog.save()
32
33>>> cat = Cat(name='Felix')
34>>> cat.say_hello()
35Felix says meaow
36>>> cat.save()
37>>> cat.name = 'Garfield'
38>>> cat.save(force_update=True)
39>>> cat.say_hello()
40Garfield says meaow
41"""}
Back to Top