python - Change form field value in django, after __init__ but before cleaning -


i want reset value of fields in django form none, inside __init__ method of form.

this have far:

class myformform(forms.modelform):     class meta:         model = mymodel         fields = ['field1', ...]      field1 = forms.integerfield(max_value=100)      def __init__(self, *args, **kwargs):         values_changed = kwargs.pop('values_changed', false)         super(myformform, self).__init__(*args, **kwargs)         self.data = self.data.copy()          if not values_changed:             field in self.fields:                 self.data[field] = none 

unfortunately, when form displayed in template, value has been posted still in it. how rid of value, change takes effect in template, renders form?

things don't work:

  • setting initial parameter. since there value present, ignored
  • using cleaned values. form not cleaned @ stage, since not valid. because of cleaned_data not exist

i'm accessing values this:

{{ form.field1.value|default_if_none:"please enter." }} 

edit: tried

{{ form.data.field1|default_if_none:"please enter." }} 

no change.

i'm moron. there 2 forms, form , form_2.

i used wrong variable name. bad. works should code above.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -