Ejemplo n.º 1
0
 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()))
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 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,
             ))
Ejemplo n.º 5
0
 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,
             )
         )
Ejemplo n.º 6
0
    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,
                )
            )
Ejemplo n.º 7
0
    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,
                ))
Ejemplo n.º 8
0
 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()))
Ejemplo n.º 9
0
 def test_proxy(self):
     # TODO: Is this the correct behavior?
     self.assertEqual('proxy', verbose_name(Proxy))
Ejemplo n.º 10
0
 def test_verbose_name(self):
     self.assertEqual('parent', verbose_name(Parent))
Ejemplo n.º 11
0
 def test_proxy(self):
     # TODO: Is this the correct behavior?
     self.assertEqual('proxy', verbose_name(Proxy))
Ejemplo n.º 12
0
 def test_verbose_name(self):
     self.assertEqual('parent', verbose_name(Parent))
Ejemplo n.º 13
0
 def to_representation(self, value):
     return verbose_name(value)
Ejemplo n.º 14
0
 def to_representation(self, value):
     return verbose_name(value)