コード例 #1
0
    def test_basic_mapping(self, assert_dict_equals):
        """
        Confirm that the serializer can still handle models w/
        standard Django fields
        """
        class TestSerializer(DjongoModelSerializer):
            class Meta:
                model = GenericModel
                fields = '__all__'

        expected_dict = {
            'id':
            drf_fields.IntegerField(label='ID', read_only=True),
            'big_int':
            drf_fields.IntegerField(max_value=9223372036854775807,
                                    min_value=-9223372036854775808),
            'bool':
            drf_fields.BooleanField(),
            'char':
            drf_fields.CharField(max_length=20),
            'comma_int':
            ("CharField(validators=[<django.core.validators.RegexValidator "
             "object>, <django.core.validators.MaxLengthValidator object>])"),
            'date':
            drf_fields.DateField(),
            'date_time':
            drf_fields.DateTimeField(),
            'decimal':
            drf_fields.DecimalField(decimal_places=5, max_digits=10),
            'email':
            drf_fields.EmailField(max_length=254),
            'float':
            drf_fields.FloatField(),
            'integer':
            drf_fields.IntegerField(max_value=2147483647,
                                    min_value=-2147483648),
            'null_bool':
            drf_fields.NullBooleanField(required=False),
            'pos_int':
            drf_fields.IntegerField(max_value=2147483647, min_value=0),
            'pos_small_int':
            drf_fields.IntegerField(max_value=32767, min_value=0),
            'slug':
            drf_fields.SlugField(allow_unicode=False, max_length=50),
            'small_int':
            drf_fields.IntegerField(max_value=32767, min_value=-32768),
            'text':
            "CharField(style={'base_template': 'textarea.html'})",
            'time':
            drf_fields.TimeField(),
            'url':
            drf_fields.URLField(max_length=200),
            'ip':
            drf_fields.IPAddressField(),
            'uuid':
            "ModelField(model_field=<django.db.models.fields.UUIDField: uuid>)",
        }

        assert_dict_equals(TestSerializer().get_fields(), expected_dict)
コード例 #2
0
 class Meta:
     param_fields = (
         ('name', fields.CharField(label='名称', max_length=64)),
         ('description',
          fields.CharField(label='描述',
                           max_length=255,
                           required=False,
                           default="")),
         ('create_user_manager',
          fields.NullBooleanField(label='创建人管理权限',
                                  required=False,
                                  default=None)),
     )
コード例 #3
0
ファイル: search.py プロジェクト: RHMTT/galaxy-quick
class SearchRequestSerializer(serializers.Serializer):
    keywords = fields.CharField(default=None)
    namespaces = SeparatedStringField(
        child=fields.RegexField(regex=constants.NAME_REGEXP),
        default=None,
    )
    names = SeparatedStringField(
        child=fields.RegexField(regex=constants.NAME_REGEXP),
        default=None,
    )
    tags = SeparatedStringField(default=None, )
    contributor_type = fields.ChoiceField(
        choices=constants.NS_TYPES,
        default=None,
    )
    platforms = SeparatedStringField(default=None)
    cloud_platforms = SeparatedStringField(default=None)
    deprecated = fields.NullBooleanField(default=None)
コード例 #4
0
class VerificationTokenSerializer(serializers.ModelSerializer):
    is_active = fields.BooleanField(read_only=True)

    comment = fields.CharField(
        max_length=VerificationToken.COMMENT_MAX_LENGTH,
        write_only=True,
    )
    is_ok = fields.NullBooleanField(write_only=True)

    class Meta:
        model = VerificationToken
        fields = ['comment', 'is_ok', 'is_active']

    def update(self, instance, validated_data):
        instance.comment = validated_data['comment']
        instance.is_ok = validated_data['is_ok']
        instance.is_confirmed = True
        instance.save()

        return instance