python对象属性对照表_Python类属性及对象属性

class Field(object):

widget = TextInput # Default widget to use when rendering this type of Field.

hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden".

default_validators = [] # Default set of validators

# Add an 'invalid' entry to default_error_message if you want a specific

# field error message not raised by the field validators.

default_error_messages = {

'required': _('This field is required.'),

}

empty_values = list(validators.EMPTY_VALUES)

# Tracks each time a Field instance is created. Used to retain order.

creation_counter = 0

def __init__(self, required=True, widget=None, label=None, initial=None,

help_text='', error_messages=None, show_hidden_initial=False,

validators=(), localize=False, disabled=False, label_suffix=None):

# required -- Boolean that specifies whether the field is required.

# True by default.

# widget -- A Widget class, or instance of a Widget class, that should

# be used for this Field when displaying it. Each Field has a

# default Widget that it'll use if you don't specify this. In

# most cases, the default widget is TextInput.

# label -- A verbose name for this field, for use in displaying this

# field in a form. By default, Django will use a "pretty"

# version of the form field name, if the Field is part of a

# Form.

# initial -- A value to use in this Field's initial display. This value

# is *not* used as a fallback if data isn't given.

# help_text -- An optional string to use as "help text" for this Field.

# error_messages -- An optional dictionary to override the default

# messages that the field will raise.

# show_hidden_initial -- Boolean that specifies if it is needed to render a

# hidden widget with initial value after widget.

# validators -- List of additional validators to use

# localize -- Boolean that specifies if the field should be localized.

# disabled -- Boolean that specifies whether the field is disabled, that

# is its widget is shown in the form but not editable.

# label_suffix -- Suffix to be added to the label. Overrides

# form's label_suffix.

self.required, self.label, self.initial = required, label, initial

self.show_hidden_initial = show_hidden_initial

self.help_text = help_text

self.disabled = disabled

self.label_suffix = label_suffix

widget = widget or self.widget

if isinstance(widget, type):

widget = widget()

else:

widget = copy.deepcopy(widget)

# Trigger the localization machinery if needed.

self.localize = localize

if self.localize:

widget.is_localized = True

# Let the widget know whether it should display as required.

widget.is_required = self.required

# Hook into self.widget_attrs() for any Field-specific HTML attributes.

extra_attrs = self.widget_attrs(widget)

if extra_attrs:

widget.attrs.update(extra_attrs)

self.widget = widget

# Increase the creation counter, and save our local copy.

self.creation_counter = Field.creation_counter

Field.creation_counter += 1 #类属性

messages = {}

for c in reversed(self.__class__.__mro__):

messages.update(getattr(c, 'default_error_messages', {}))

messages.update(error_messages or {})

self.error_messages = messages

self.validators = list(itertools.chain(self.default_validators, validators))

super(Field, self).__init__()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值