mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Fix failing 'default' on ModelSerializer
This commit is contained in:
parent
fc4614a89c
commit
67f1265e49
|
@ -410,7 +410,7 @@ class ModelSerializer(Serializer):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if model_field.has_default():
|
if model_field.has_default():
|
||||||
kwargs['required'] = False
|
kwargs['required'] = False
|
||||||
kwargs['default'] = model_field.default
|
kwargs['default'] = model_field.get_default()
|
||||||
|
|
||||||
if model_field.__class__ == models.TextField:
|
if model_field.__class__ == models.TextField:
|
||||||
kwargs['widget'] = widgets.Textarea
|
kwargs['widget'] = widgets.Textarea
|
||||||
|
|
|
@ -42,6 +42,7 @@ class ActionItemSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ActionItem
|
model = ActionItem
|
||||||
|
|
||||||
|
|
||||||
class BasicTests(TestCase):
|
class BasicTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.comment = Comment(
|
self.comment = Comment(
|
||||||
|
@ -131,7 +132,7 @@ class ValidationTests(TestCase):
|
||||||
"""Make sure that a boolean value with a 'False' value is not
|
"""Make sure that a boolean value with a 'False' value is not
|
||||||
mistaken for not having a default."""
|
mistaken for not having a default."""
|
||||||
data = {
|
data = {
|
||||||
'title':'Some action item',
|
'title': 'Some action item',
|
||||||
#No 'done' value.
|
#No 'done' value.
|
||||||
}
|
}
|
||||||
serializer = ActionItemSerializer(data, instance=self.actionitem)
|
serializer = ActionItemSerializer(data, instance=self.actionitem)
|
||||||
|
@ -296,10 +297,12 @@ class ManyToManyTests(TestCase):
|
||||||
self.assertEquals(instance.pk, 2)
|
self.assertEquals(instance.pk, 2)
|
||||||
self.assertEquals(list(instance.rel.all()), [])
|
self.assertEquals(list(instance.rel.all()), [])
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyManyToManyTests(TestCase):
|
class ReadOnlyManyToManyTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
class ReadOnlyManyToManySerializer(serializers.ModelSerializer):
|
class ReadOnlyManyToManySerializer(serializers.ModelSerializer):
|
||||||
rel = serializers.ManyRelatedField(readonly=True)
|
rel = serializers.ManyRelatedField(readonly=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ReadOnlyManyToManyModel
|
model = ReadOnlyManyToManyModel
|
||||||
|
|
||||||
|
@ -317,7 +320,6 @@ class ReadOnlyManyToManyTests(TestCase):
|
||||||
# A serialized representation of the model instance
|
# A serialized representation of the model instance
|
||||||
self.data = {'rel': [self.anchor.id], 'id': 1, 'text': 'anchor'}
|
self.data = {'rel': [self.anchor.id], 'id': 1, 'text': 'anchor'}
|
||||||
|
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""
|
"""
|
||||||
Attempt to update an instance of a model with a ManyToMany
|
Attempt to update an instance of a model with a ManyToMany
|
||||||
|
|
Loading…
Reference in New Issue
Block a user