def test_deferred_query(self): # `defer`red and `only` queries mangle the `verbose_name` attribute with # a list of the query's deferred fields. self.assertEqual('parent', verbose_name(Parent.objects.only('pk').first())) self.assertEqual( 'parent', verbose_name(Parent.objects.defer('parent_field').first()))
def get_resource_type(self, instance): """ Returns the resource type for a given model. Currently this defaults to the verbose_name of the model. instance may be either a model class or an instance. """ return model_meta.verbose_name(instance)
def get_resource_type(self, instance): """ Returns the resource type for a given model. Currently this defaults to the verbose_name of the model. instance may be either a model class or an instance. """ return model_meta.verbose_name(instance)
def validate_type(self, data): expected = verbose_name(self.parent.Meta.model) if data != expected: raise serializers.ValidationError( 'Incorrect type. Expected \'{}\', but got \'{}\'.'.format( expected, data, ))
def validate_type(self, data): expected = verbose_name(self.parent.Meta.model) if data != expected: raise serializers.ValidationError( 'Incorrect type. Expected \'{}\', but got \'{}\'.'.format( expected, data, ) )
def validate_type(self, data): models = [self.parent.Meta.model] + list(self.parent.Meta.subtypes) expected = [verbose_name(model) for model in models] if data not in expected: raise serializers.ValidationError( 'Incorrect type. Expected any in \'{}\', but got \'{}\'.'.format( expected, data, ) )
def validate_type(self, data): models = [self.parent.Meta.model] + list(self.parent.Meta.subtypes) expected = [verbose_name(model) for model in models] if data not in expected: raise serializers.ValidationError( 'Incorrect type. Expected any in \'{}\', but got \'{}\'.'. format( expected, data, ))
def test_deferred_query(self): # `defer`red and `only` queries mangle the `verbose_name` attribute with # a list of the query's deferred fields. self.assertEqual('parent', verbose_name(Parent.objects.only('pk').first())) self.assertEqual('parent', verbose_name(Parent.objects.defer('parent_field').first()))
def test_proxy(self): # TODO: Is this the correct behavior? self.assertEqual('proxy', verbose_name(Proxy))
def test_verbose_name(self): self.assertEqual('parent', verbose_name(Parent))
def test_proxy(self): # TODO: Is this the correct behavior? self.assertEqual('proxy', verbose_name(Proxy))
def test_verbose_name(self): self.assertEqual('parent', verbose_name(Parent))
def to_representation(self, value): return verbose_name(value)
def to_representation(self, value): return verbose_name(value)