django - add extra field to ModelForm -
i adding field django modelform that:
class form(forms.modelform): extra_field = forms.charfield(label='name of institution') class meta: model = db_institutioninstitution fields = ['conn_kind','time','inst_name2']
the form working fine, cant prepopulate it. use in modelformset_factory
:
formset = modelformset_factory(db_institutioninstitution,form=form)
i manually run through queryset , add entry in dictionary needed additional form in formset. however, when call:
formset1 = formset(prefix='brch',queryset=qs1)
the extra_field
not prepopulated intended (the rest working fine).
can help?
if want set default.
extra_field = forms.charfield(label='name of institution', default="harvard")
if want dynamically set value:
def __init__(self, *args, **kwargs): super(form,self).__init(*args, **kwargs) self.fields['extra_field'].initial = "harvard"
Comments
Post a Comment