11 lines
632 B
Python
11 lines
632 B
Python
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 you’re 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') |