当前位置: 首页>>代码示例>>Python>>正文


Python ModelForm.__init__方法代码示例

本文整理汇总了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()
开发者ID:DimitriyNikolaev,项目名称:fiesta,代码行数:10,代码来源:forms.py

示例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))
开发者ID:satyadevi-nyros,项目名称:eracks,代码行数:10,代码来源:admin.py

示例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)
开发者ID:roldandvg,项目名称:incidencias,代码行数:11,代码来源:forms.py

示例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
开发者ID:debon,项目名称:comt,代码行数:13,代码来源:user.py

示例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
开发者ID:clarkcui89,项目名称:papermache,代码行数:13,代码来源:texts.py

示例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"})
开发者ID:sergeyshepel,项目名称:FortyTwoTestTask,代码行数:15,代码来源:forms.py

示例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))
开发者ID:satyadevi-nyros,项目名称:eracks,代码行数:16,代码来源:admin.py

示例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
开发者ID:karawana,项目名称:GenGoZ,代码行数:20,代码来源:admin.py

示例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)
开发者ID:pclements12,项目名称:PyWishlist,代码行数:21,代码来源:ItemForm.py

示例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()
开发者ID:ITIDO,项目名称:rapidsms,代码行数:5,代码来源:views.py

示例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')
开发者ID:450514,项目名称:password,代码行数:6,代码来源:forms.py

示例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)
开发者ID:caporeista,项目名称:yasinyaman.com,代码行数:6,代码来源:forms.py

示例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')]
开发者ID:pratz,项目名称:onekey,代码行数:8,代码来源:forms.py

示例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')
开发者ID:MERegistro,项目名称:meregistro,代码行数:6,代码来源:RolForm.py

示例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
开发者ID:tyarkoni,项目名称:NeuroVault,代码行数:8,代码来源:forms.py


注:本文中的django.forms.ModelForm.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。