當前位置: 首頁>>代碼示例>>Python>>正文


Python validators.UniqueValidator方法代碼示例

本文整理匯總了Python中rest_framework.validators.UniqueValidator方法的典型用法代碼示例。如果您正苦於以下問題:Python validators.UniqueValidator方法的具體用法?Python validators.UniqueValidator怎麽用?Python validators.UniqueValidator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.validators的用法示例。


在下文中一共展示了validators.UniqueValidator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_standard_field

# 需要導入模塊: from rest_framework import validators [as 別名]
# 或者: from rest_framework.validators import UniqueValidator [as 別名]
def build_standard_field(self, field_name, model_field):
        field_class, field_kwargs = super(
            NaturalKeySerializer, self
        ).build_standard_field(field_name, model_field)

        if 'validators' in field_kwargs:
            field_kwargs['validators'] = [
                validator
                for validator in field_kwargs.get('validators', [])
                if not isinstance(validator, UniqueValidator)
            ]
        return field_class, field_kwargs 
開發者ID:wq,項目名稱:django-natural-keys,代碼行數:14,代碼來源:serializers.py

示例2: __init__

# 需要導入模塊: from rest_framework import validators [as 別名]
# 或者: from rest_framework.validators import UniqueValidator [as 別名]
def __init__(self, queryset, message=None, lookup=''):
        """
        Setting empty string as default lookup for UniqueValidator.
        For Mongoengine exact is a shortcut to query with regular experission.
        This fixes https://github.com/umutbozkurt/django-rest-framework-mongoengine/issues/264
        """
        super(UniqueValidator, self).__init__(queryset, message, lookup) 
開發者ID:umutbozkurt,項目名稱:django-rest-framework-mongoengine,代碼行數:9,代碼來源:validators.py

示例3: get_relation_kwargs

# 需要導入模塊: from rest_framework import validators [as 別名]
# 或者: from rest_framework.validators import UniqueValidator [as 別名]
def get_relation_kwargs(field_name, relation_info):
    """
    Creates a default instance of a flat relational field.
    """
    model_field, related_model, to_many, to_field, has_through_model, reverse = relation_info
    kwargs = {
        'queryset': related_model._default_manager,
        'view_name': get_detail_view_name(related_model)
    }

    if to_many:
        kwargs['many'] = True

    if to_field:
        kwargs['to_field'] = to_field

    if has_through_model:
        kwargs['read_only'] = True
        kwargs.pop('queryset', None)

    if model_field:
        if model_field.verbose_name and needs_label(model_field, field_name):
            kwargs['label'] = capfirst(model_field.verbose_name)
        help_text = model_field.help_text
        if help_text:
            kwargs['help_text'] = help_text
        if not model_field.editable:
            kwargs['read_only'] = True
            kwargs.pop('queryset', None)
        if kwargs.get('read_only', False):
            # If this field is read-only, then return early.
            # No further keyword arguments are valid.
            return kwargs

        if model_field.has_default() or model_field.blank or model_field.null:
            kwargs['required'] = False
        if model_field.null:
            kwargs['allow_null'] = True
        if model_field.validators:
            kwargs['validators'] = model_field.validators
        if getattr(model_field, 'unique', False):
            validator = UniqueValidator(queryset=model_field.model._default_manager)
            kwargs['validators'] = kwargs.get('validators', []) + [validator]
        if to_many and not model_field.blank:
            kwargs['allow_empty'] = False

    return kwargs 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:49,代碼來源:field_mapping.py


注:本文中的rest_framework.validators.UniqueValidator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。