Serializer Base Classes¶
This module holds base classes that are derived off of the rest framework serializer base serializers, but with some additional capabilities added on that are useful in aspects here.
-
class
recipes.serializers.base.
CreatorBaseSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs) Bases:
rest_framework.serializers.ModelSerializer
This base class provides a method for getting a creator object serialized properly. This includes creating a serializer method field named creator that should match up with the underlying model being serialized (i.e. it should also have a creator model field). This also includes writing a get_creator method that will be used to extract the creator from the model instance.
-
creator
= None The creator field is a read-only serializer method field. Internally the base class’s to_representation method will call the get_creator method when serializing the object for output
-
get_creator
(created_instance) This worker function will get a creator from a class that has that field, or else return a blank string
Parameters: created_instance – A Python model object, or really any object that has a creator member variable - not a dict Returns: A string, either the creator name or a blank string
-