Add id in serializer

This commit is contained in:
keannu125 2023-03-06 15:38:47 +08:00
parent 96ab7ed1d4
commit c486b12f33

View file

@ -5,8 +5,9 @@ from .models import Product
class ProductSerializer(serializers.HyperlinkedModelSerializer):
date_added = serializers.DateTimeField(
format="%d-%m-%Y %I:%M%p", read_only=True)
quantity = serializers.IntegerField(required=False, default=0)
class Meta:
model = Product
fields = ('name', 'quantity', 'date_added')
fields = ('id', 'name', 'quantity', 'date_added')
read_only_fields = ('id', 'date_added')