News for hackers. Stuff that matters.
Re:Django Rest Framework general model serializer by andybak on Friday January 30, 2015 @07:08AM (#8971629)
Django does this out of the box: https://docs.djangoproject.com/en/1.7/topics/serialization/

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.

Re:Django Rest Framework general model serializer by norbert_mate on Friday January 30, 2015 @07:37AM (#8971695)
Correct. It's very easy to create a simple model serializer and this is what the general model serializer does. It's no big deal just saves a few line of code.
Re:Django Rest Framework general model serializer by whalesalad on Friday January 30, 2015 @12:05PM (#8972941)
You say "out of the box" but it's not that simple... 'blah blah DateTime is not JSON serializable'
Re:Django Rest Framework general model serializer by andybak on Saturday January 31, 2015 @08:55PM (#8978874)
Just tried it:

    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}]