本文整理汇总了Python中django.forms.ModelForm.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ModelForm.__init__方法的具体用法?Python ModelForm.__init__怎么用?Python ModelForm.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.ModelForm
的用法示例。
在下文中一共展示了ModelForm.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self,*args,**kwargs):
ModelForm.__init__(self,*args,**kwargs)
#first argument, index is the position of the field you want it to come before
self.fields.insert(6,'time_added',forms.TimeField(widget=JSDateTimePickerWidget(), input_formats=('%H:%M',), required=True))
if not self.instance.id:
self.instance.date_added = utc.localize(datetime.datetime.today())
self.fields['time_added'].initial = self.instance.date_added.time()
示例2: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__ (self, *args, **kw):
ModelForm.__init__ (self, *args, **kw)
if self.instance and isinstance (self.instance, Prodopt):
inst=self.instance
dc=self.fields.get('defaultchoice')
if trace: print inst.all_choices # option_id # dir (inst)
if inst.pk and inst.all_choices().count():
dc.queryset = inst.all_choices() #Choice.objects.filter (id__in = inst.choices.values_list('id', flat=True))
示例3: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, division=None, *args, **kwargs):
ModelForm.__init__(self, *args, **kwargs)
self.fields['municipio'].choices = cargar_municipio()
if division:
# Evalúa si se estableció el tipo de novedad a registrar de acuerdo a la división indicada, en caso
# contrario muestra un listado con todos los tipos de procedimientos registrados
self.fields['tipo_procedimiento'].choices = cargar_tipo_procedimiento(division)
示例4: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=':',
empty_permitted=False, instance=None):
ModelForm.__init__(self, data, files, auto_id, prefix, initial, error_class, label_suffix, empty_permitted, instance)
# override manually
role_field = self.fields['role']
role_field.required = False
role_field.choices = [(u'', u'---------')] + [(r.id, str(r)) for r in Role.objects.filter(anon=True)] # limit anon choices
self.fields['role'] = role_field
示例5: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=':',
empty_permitted=False, instance=None):
ModelForm.__init__(self, data, files, auto_id, prefix, initial, error_class, label_suffix, empty_permitted, instance)
# override manually to disabled
format_field = self.fields['format']
format_field.widget.attrs = {'disabled':'disabled'}
format_field.required = False
self.fields['format'] = format_field
示例6: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
if "instance" in kwargs:
initial = kwargs.setdefault("initial", {})
initial["teams"] = [team.pk for team in kwargs["instance"].team_set.all()]
ModelForm.__init__(self, *args, **kwargs)
super(PersonForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
if field != "person_pic":
self.fields[field].widget.attrs.update({"class": "form-control"})
示例7: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__ (self, *args, **kw):
ModelForm.__init__ (self, *args, **kw)
#self.fields ['choices'].queryset = Choice.objects.published() # so only published appear in slider
cf = self.fields.get ('choices', '')
if cf:
cf.queryset = Choice.objects.published() # so only published appear in slider
if self.instance and isinstance (self.instance, Prodopt):
inst=self.instance
dc=self.fields.get('defaultchoice')
if trace: print inst.all_choices # option_id # dir (inst)
if inst.pk and inst.all_choices().count():
dc.queryset = inst.all_choices() #Choice.objects.filter (id__in = inst.choices.values_list('id', flat=True))
示例8: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
instance = kwargs.get('instance', None)
if instance:
book = instance.book
else:
book = Word.objects.order_by('-create_dt')[0].book
kwargs['initial'] = {'book': book}
ModelForm.__init__(self, *args, **kwargs)
queryset = Word.objects.filter(book=book)
if instance:
queryset = queryset.exclude(pk=instance.pk)
self.fields['related'].queryset = queryset
self.fields['synonym'].queryset = queryset
self.fields['antonym'].queryset = queryset
示例9: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
# Only in case we build the form from an instance
# (otherwise, 'groups' list should be empty)
if 'instance' in kwargs:
# We get the 'initial' keyword argument or initialize it
# as a dict if it didn't exist.
initial = kwargs.setdefault('initial', {})
# The widget for a ModelMultipleChoiceField expects
# a list of primary key for the selected data.
initial['groups'] = [grp.pk for grp in kwargs['instance'].wishlistgroup_set.all()]
if 'group' in kwargs:
initial = kwargs.setdefault('initial', {})
groups = initial.setdefault('groups', [])
groups.append(kwargs['group'].pk)
del kwargs['group']
user = kwargs.pop('user')
ModelForm.__init__(self, *args, **kwargs)
self.fields['groups'].queryset = WishlistGroup.get_groups_by_user(user=user)
示例10: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
ModelForm.__init__(self, *args, **kwargs)
self.fields['patient_id'].widget = HiddenInput()
示例11: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
ModelForm.__init__(self, *args, **kwargs)
self.fields.pop('work')
self.fields.pop('notwork')
示例12: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, data=None, *args, **kwargs):
if data=={}:
data=None
ModelForm.__init__(self, data, *args, **kwargs)
示例13: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, data=None, files=None, auto_id=None, prefix=None, initial=None,
error_class=None, label_suffix=':', empty_permitted=False, instance=None) :
""" Constructor for AuthorForm Class """
ModelForm.__init__(self, data=None, files=None, auto_id=None, prefix=None, initial=None,
error_class=None, label_suffix=':', empty_permitted=False, instance=None)
self.base_fields['title'].choices = [(0,'zero'),(1,'one')]
示例14: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kw):
ModelForm.__init__(self, *args, **kw)
if kw.has_key('instance'):
self.fields['padre'].queryset = Rol.objects.exclude(id=kw['instance'].id).order_by('descripcion')
示例15: __init__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __init__ [as 别名]
def __init__(self, *args, **kwargs):
ImageValidationMixin.__init__(self, *args, **kwargs)
ModelForm.__init__(self, *args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False