from rest_framework import serializers
from . import models


class Category(serializers.ModelSerializer):
    class Meta:
        model = models.Category


class Task(serializers.ModelSerializer):
    class Meta:
        model = models.Task


from rest_framework import serializers
from django.contrib.auth import get_user_model
from . import models


class Category(serializers.ModelSerializer):
    class Meta:
        model = models.Category
        fields = ('id', 'name')


class Task(serializers.ModelSerializer):
    owner = serializers.SlugRelatedField(
        slug_field='username',
        queryset=get_user_model().objects.all())
    categories = serializers.SlugRelatedField(
        slug_field='name',
        queryset=models.Category.objects.all(),
        many=True)

    class Meta:
        model = models.Task
        fields = ('id', 'name', 'owner', 'categories', 'done')


Add human readable owner & categories.
Add human readable owner & categories.

  from rest_framework import serializers
+ from django.contrib.auth import get_user_model
  from . import models
  
  
  class Category(serializers.ModelSerializer):
      class Meta:
          model = models.Category
+         fields = ('id', 'name')
  
  
  class Task(serializers.ModelSerializer):
+     owner = serializers.SlugRelatedField(
+         slug_field='username',
+         queryset=get_user_model().objects.all())
+     categories = serializers.SlugRelatedField(
+         slug_field='name',
+         queryset=models.Category.objects.all(),
+         many=True)
+ 
      class Meta:
          model = models.Task
+         fields = ('id', 'name', 'owner', 'categories', 'done')
  
  
Add human readable owner & categories.
## Code Before:
from rest_framework import serializers
from . import models


class Category(serializers.ModelSerializer):
    class Meta:
        model = models.Category


class Task(serializers.ModelSerializer):
    class Meta:
        model = models.Task


## Instruction:
Add human readable owner & categories.
## Code After:
from rest_framework import serializers
from django.contrib.auth import get_user_model
from . import models


class Category(serializers.ModelSerializer):
    class Meta:
        model = models.Category
        fields = ('id', 'name')


class Task(serializers.ModelSerializer):
    owner = serializers.SlugRelatedField(
        slug_field='username',
        queryset=get_user_model().objects.all())
    categories = serializers.SlugRelatedField(
        slug_field='name',
        queryset=models.Category.objects.all(),
        many=True)

    class Meta:
        model = models.Task
        fields = ('id', 'name', 'owner', 'categories', 'done')

