by andybak · 11y ago · 0 comments
But DRF adds lots of extra functionality. Even with DRF it's as simple as adding:
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
to get full automatic serialization of a model.> I don't know if serializing child objects is really a good idea
Depends on the specific case. For internal APIs I tend to create endpoints that give a view what it needs in a single request.
from django.core import serializers
print serializers.serialize("json", StockCount.objects.all()[:2])
>> [{"fields": {"timestamp": "1900-01-02T00:00:00Z", "version": 0, "item_instance": null, "item_model": 408, "stock_level": 999, "location": 2}, "model": "stocklevels.stockcount", "pk": 1}, {"fields": {"timestamp": "1900-01-02T00:00:00Z", "version": 0, "item_instance": null, "item_model": 409, "stock_level": 999, "location": 2}, "model": "stocklevels.stockcount", "pk": 2}]