Get list of fileds from reverse relationship

I am trying to get the list of count of a field based on date so I can plot stacked bar graph on frontend. These are my models:


class BaseModel(models.Model):
    id: int
    created_at = models.DateTimeField(verbose_name="Created", auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name="Last Updated", auto_now=True)

    class Meta:
        abstract = True

class A(BaseModel):

    name = models.CharField(max_length=512, null=True, blank=True)


class B(BaseModel):
    a = models.ForeignKey(A, on_delete=models.CASCADE)


class C(BaseModel):
    b = models.ForeignKey(B, on_delete=models.CASCADE)

I am trying to get the count (as list) of B and C when getting the list of A for last 7 days. But I am getting count instead not an object.

Using recharts on frontend, my desired output format will be (using sample data from internet):


{
  "items": [
    {
      "name": "android app",
      "chart_data": [
        {
          "name": "A",
          "x": 12,
          "y": 23,
          "z": 122
        },
        {
          "name": "B",
          "x": 22,
          "y": 3,
          "z": 73
        },
        {
          "name": "C",
          "x": 13,
          "y": 15,
          "z": 32
        }
      ]
    },
    {
      "name": "My",
      "chart_data": [
        {
          "name": "A",
          "x": 12,
          "y": 23,
          "z": 122
        },
        {
          "name": "B",
          "x": 22,
          "y": 3,
          "z": 73
        },
        {
          "name": "C",
          "x": 13,
          "y": 15,
          "z": 32
        }
      ]
    }
  ]
}
Back to Top