I'm working on a small project ( Kanban board ) using Django / Rest Framework, I have two models one for tasks and one another for status ( columns ), like ( started, pending, Done ).
everything works fine with me. the only issue I have is my data structure, is not correctly nested,
this is my models : (Status)
from django.db import models
from django.conf import settings
from contact.models import Contact
# Create your models here.
class Status(models.Model):
title = models.CharField(blank=False, null=False, max_length=255)
slug = models.CharField(blank=False, null=False, max_length=255)
order = models.SmallIntegerField(default=0)
def __str__(self):
return self.title
This is my Task Model :
class Task(models.Model):
status = models.ForeignKey(Status, on_delete=models.CASCADE, default=1)
title = models.CharField(blank=False, max_length=255)
This is my serializer :
from rest_framework import serializers
from task.models import Task
class TaskSerializer(serializers.ModelSerializer):
class Meta:
model = Task
fields = '__all__'
depth = 1
The result that i get :
[
{
"id": 1,
"title": "my task title must be inside status ",
"status": {
"id": 1,
"title": "step1",
"slug": "step1",
"order": 1
}
}
]
**I would like to get a nested Data structure, my tasks my be inside the status dictionary, so I can loop ever the status and the tasks ( nested for loop )