tomchristie/django-rest-framework — pull request #1088 by craigds (2013-09-06 04:26:23+00:00)
Title: Make modelserializer support writable properties on models it instantiates

ModelSerializer doesn't currently allow you to create objects where the fields are sourced from writable properties.

The cause is that it passes all the non-relational fields directly into Model(**attrs). If anything is in there that's not a django model field, it throws an error.

This fixes that problem, including a test for the broken behaviour.

I should note that my fix caused a failure in `ValidationTests.test_writable_star_source_on_nested_serializer`, but that's because it was doing something dumb (updating a model with a value for a read-only property). That silently failed before and now throws:

*** AttributeError: can't set attribute

... which seems like the correct behaviour in that case. I fixed that test by making the property writable.