From e207585bb7b49ed15211ba712a27490843f25496 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 21 Oct 2020 15:09:51 +1100 Subject: [PATCH] Finished serializer for puppies --- puppy_store/puppies/serializers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 puppy_store/puppies/serializers.py diff --git a/puppy_store/puppies/serializers.py b/puppy_store/puppies/serializers.py new file mode 100644 index 0000000..eccfd09 --- /dev/null +++ b/puppy_store/puppies/serializers.py @@ -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') \ No newline at end of file