I am struggling with django app design. Given the following models:
class A(models.Model):
name = models.CharField(max_length=255)
class B(models.Model):
name = models.CharField(max_length=255)
a = models.ForeignKey(A)
class C(models.Model):
val = models.IntegerField()
b = models.ForeignKey(B)
I would like the view / template to display an HTML table that shows all objects A in the first column, all B objects (grouped by A) that A refer to in the second column, and the sum of all val objects from C in the last column, which apply to each B. All this with a sum for each object A. The following example shows what I'm looking for:
A1.name | B1.name [where FK to A1] | sum (C.val) [where FK to B1]
A1.name | B2.name [where FK to A1] | sum (C.val) [where FK to B2]
A1.name | Total | sum (C.val) [where FK to Bx (all B that have FK to A1]
A2.name | B3.name [where FK to A2] | sum (C.val) [where FK to B3]
A2.name | Total | sum (C.val) [where FK to Bx (all B that have FK to A2]
Can someone give me advice on how to develop such a problem (unfortunately, my code often ends up in quite a mess)?
Should I extend model classes using appropriate methods? Does the user query do all the tabular data in the view? Just get all the objects through the managers and do most of the things in the template?
Thanks for every reply.
Hello,
Bows.
Lukas source
share