Finished serializer for puppies

master
Jason Zhu 2020-10-21 15:09:51 +11:00
parent d03f9c7a5b
commit e207585bb7
1 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,11 @@
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')