# Retrieve subcategories with all the details next to the parent category

**URL:** <https://forum.djangoproject.com/t/retrieve-subcategories-with-all-the-details-next-to-the-parent-category/11779>\
**Category:** Using Django\
**Created:** [January 25, 2022, 8:17am UTC](https://forum.djangoproject.com/t/retrieve-subcategories-with-all-the-details-next-to-the-parent-category/11779 "2022-01-25T08:17:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dani-D99](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dani-d99/32/4755_2.png) [@Dani-D99](https://forum.djangoproject.com/u/Dani-D99)\
**Post date:** [January 25, 2022, 8:17am UTC](https://forum.djangoproject.com/t/retrieve-subcategories-with-all-the-details-next-to-the-parent-category/11779/1 "2022-01-25T08:17:34Z")

</div>

Hi, for example, when I retrieve the categories from the database, they come in the following way

```auto
{
"name": "Milk",
 "slug": "milk"
 "parent": ""
}

```

But how could I take a sub json with the child categories

```auto
{
"name": "Milk",
 "slug": "milk"
 "parent": "",
  subcategoies: {
  "name": "Strawberies milk",
  "slug": "strawberies-milk"
  "parent": " c5ecbde1-cbf4-11e5-a759-6096cb89d9a5"
  }
}

```

This is my code

```auto
import uuid
from django.db import models

class Category(models.Model):
    DoesNotExist = None
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(verbose_name='category name', max_length=50)
    slug = models.SlugField()
    parent = models.ForeignKey('self', blank=True, null=True, related_name='children', on_delete=models.CASCADE)

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__ (self):
        full_path = [self.name]
        k = self.parent
        while k is not None:
            full_path.append(k.name)
            k = k.parent
        return ' -> '.join(full_path[::-1])

```

Serializer

```auto
from rest_framework import serializers
from ..models.Category import Category

class CategorySerializer(serializers.ModelSerializer):

    class Meta:
        model = Category
        fields = ('id', 'name', 'slug', 'parent', 'created', 'updated')
        unique_together = ('slug', 'parent',)

```

```auto
class CategoryAPIView(generics.GenericAPIView):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer
    permission_classes = [IsAuthenticated]

    def get(self, request, id):
        category = Category.objects.get(id=id)
        category_serializer = CategorySerializer(category, many=True)

        return Response({'data': category_serializer.data}, status=200)

```

How can I change this queryset?
