Merge pull request #491 from markotibold/#490

get_excluded_fieldnames() should respect Meta options' ability to be eit...
This commit is contained in:
Tom Christie 2012-12-11 00:55:12 -08:00
commit e20b0bc45b
2 changed files with 7 additions and 4 deletions

View File

@ -132,9 +132,9 @@ class BaseSerializer(Field):
Returns the fieldnames that should not be validated. Returns the fieldnames that should not be validated.
""" """
excluded_fields = list(self.opts.exclude) excluded_fields = list(self.opts.exclude)
for field in self.fields.keys() + self.get_default_fields().keys(): if self.opts.fields:
if self.opts.fields: for field in self.fields.keys() + self.get_default_fields().keys():
if field not in self.opts.fields + self.opts.exclude: if field not in list(self.opts.fields) + excluded_fields:
excluded_fields.append(field) excluded_fields.append(field)
return excluded_fields return excluded_fields

View File

@ -66,6 +66,7 @@ class AlbumsSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Album model = Album
fields = ['title'] # lists are also valid options
class BasicTests(TestCase): class BasicTests(TestCase):
@ -282,9 +283,11 @@ class ValidationTests(TestCase):
self.assertEquals(serializer.is_valid(), False) self.assertEquals(serializer.is_valid(), False)
self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']}) self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']})
class ModelValidationTests(TestCase):
def test_validate_unique(self): def test_validate_unique(self):
""" """
Just check if serializers.ModelSerializer.perform_model_validation() handles unique checks via .full_clean() Just check if serializers.ModelSerializer handles unique checks via .full_clean()
""" """
serializer = AlbumsSerializer(data={'title': 'a'}) serializer = AlbumsSerializer(data={'title': 'a'})
serializer.is_valid() serializer.is_valid()