This problem can be solved by adding
if obj is None and self.default is not None:
return self.default
to rest_framework/fields.py
Original pull request: https://github.com/tomchristie/django-rest-framework/pull/1248/files
Вопрос
Using django 1.6 and rest framework 2.3.13
In model class:
class A(models.Model):
some_name = models.PositiveSmallIntegerField(default=15)
In serilizer:
class ASerializer(ModelSerializer):
class Meta:
model = A
fields = ( 'some_name' )
In view:
class AViewSet(viewsets.ModelViewSet):
queryset = A.objects.all()
serializer_class = ASerializer
But in the api form, it's showing as 0, any idea?
Решение
This problem can be solved by adding
if obj is None and self.default is not None:
return self.default
to rest_framework/fields.py
Original pull request: https://github.com/tomchristie/django-rest-framework/pull/1248/files