11 lines
632 B
Python
Raw Normal View History

2020-10-21 15:09:51 +11:00
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')