Model ineritance problem

6 views
Skip to first unread message

juanefren

unread,
Aug 20, 2009, 3:14:35 AM8/20/09
to Django users
Having these Models...

class Parent(models.Model):
date = models.DateField()
n = models.IntegerField(default = 0)

class Kind1(Parent):
def total(self):
return cantidad * 3

class Kind2(Parent):
def total(self):
return cantidad * 2

How can I do this ?
for p in Parent.objects.all().order_by('-date'):
print p.total() #this should print self.n * 2 or self.n * 3
depending the case

What I did was:
k1 = Kind1.objects.all().order_by('-date')
k2 = Kind2.objects.all().order_by('-date')
objects = itertools.chain(k1, k2)
for o in objects:
print o.total()

But I think is not a correct solution, what do you think ?
Reply all
Reply to author
Forward
0 new messages