11 lines
632 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from rest_framework import serializers
from rest_framework.exceptions import MethodNotAllowed
from .models import Puppy
class PuppySerializer(serializers.ModelSerializer):
"""
In the above snippet we defined a ModelSerializer for our puppy model, validating all the mentioned fields. In short, if you have a one-to-one relationship between your API endpoints and your models - which you probably should if youre creating a RESTful API - then you can use a ModelSerializer to create a Serializer.
"""
class Meta:
model = Puppy
fields = ('name', 'age', 'breed', 'color', 'created_at', 'updated_at')