In my app I have the following models: Products, Orders and OrderEntries
Orders are made out of OrderEntries, which represent each row in a shopping cart and are made out of the Product and the amount.
Now, what I want to do with my rest api is the ability to create Order objects by posting an array of OrderEntries to /api/orders, which would validate the array and then create new OrderEntries and the final Order object.
How would I do something like that in rest-framework?
EDIT: How my serializers look like now:
class ProductSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Product
fields = ('pk', 'name', 'author', 'description', 'imageUrl', 'thumbUrl', 'price')
class OrderEntrySerializer(serializers.PrimaryKeyRelatedField, serializers.ModelSerializer):
class Meta:
model = OrderEntry
fields = ("pk", "product", "amount")
class OrderSerializer(serializers.HyperlinkedModelSerializer):
entries = OrderEntrySerializer(many=True, queryset=OrderEntry.objects.all())
class Meta:
model = Order
fields = ("pk", "order_state", "entries")
Which would require me to post the following to /orders:
{
"order_state": "string",
"entries": [
"string"
]
}
What I want is to just post the following, the state field would be set during creation:
{
"entries": [
ProductEntry,
...
]
}