I am using the Django REST framework to create an API. I would like to add data from more than one model to the serialised output.
At the moment my serialiser looks like this:
class ItemSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Item
fields = ('url', 'owner', 'item_type')
I would like to add an
item_cost
value from my Costs model to the serialised output (a different cost for each item in the Item model). I would also like to add a unix timestamp value to the serialised output (one value to be placed at the end of all of the other serialised output).
My serialiser is used in a view as follows:
class ItemViewSet(viewsets.ModelViewSet):
queryset = Item.objects.all().order_by('-date_added')
serializer_class = ItemSerializer
I can't work out how to add the other data items to the serialised output.