performing different functionality on modelform buttons django -


i have modelform 2 buttons , want perform different functionality on them. modelform:

class jobpostform(modelform):     class meta:          model = jobpost         fields = ('job_title','job_type','job_location','job_description','start_date','end_date','country','how_to_apply')      widgets = {          'job_type':radioselect(),             'job_location':textinput(attrs={'size':'70'}),            'job_description':textarea(attrs={'cols':200, 'rows':10}),             'start_date':textinput(attrs={                 'class': 'datepicker',                 'data-date-format': 'mm/dd/yyyy',               }),             'end_date':textinput(attrs={                 'class': 'datepicker',                 'data-date-format': 'mm/dd/yyyy',              }),      }      def __init__(self, *args, **kwargs):         #super(jobpostform, self).__init__(*args, **kwargs)         #self.fields['start_date'].widget.attrs['class'] = 'datepicker'         super(jobpostform, self).__init__(*args, **kwargs)         #self.fields['ref_id'].widget = forms.hiddeninput()         self.helper = formhelper()         self.helper.form_class = 'horizontal-form'         self.helper.form_id = 'id-jobpostform'         self.helper.form_class = 'blueforms'         self.helper.form_method = 'post'          self.helper.form_action = '/portal/next/post/'          self.helper.add_input(submit('submit_addcontent', 'preview'))         self.helper.add_input(submit('submit_addcontent', 'submit'))           super(jobpostform, self).__init__(*args, **kwargs) 

i want perform different functionality on submit , preview.how can access them in view?

a django form handles 2 things:

  • displaying intitial form on request
  • processing post requests data

you can approach situation in multiple ways. 1 way have both buttons submit form. preview button fill in hidden field named preview. form process submitted data. if data included value in post field named preview render preview. otherwise, process form normally.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -