Missing default value from ModelSerializer

Author: dudukleinCreated Mar 12, 2015Updated Dec 14, 2025

When creating a serializer from a model, the default value is not included in the serializer. I thought it was a bug and I was going to try to fix it and make a pull request, but I ran into the test suite and may be this is the expected behavior.

In the file django-rest-framework/tests/test_model_serializer.py, the FieldOptionsModel has a field declared as default_field = models.IntegerField(default=0).

In the test TestRegularFieldMappings.test_field_options, the expected serializer should contain default_field = IntegerField(required=False), which does not include the default value of 0.

I would expect to have default_field = IntegerField(default=0) (which would also imply required=False) or default_field = IntegerField(default=0, required=False)

Is this the expected behavior or a bug?

Source: encode/django-rest-framework