Finished serializer for puppies
parent
d03f9c7a5b
commit
e207585bb7
|
@ -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 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')
|
Loading…
Reference in New Issue