You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 ?