Skip to content

Instantly share code, notes, and snippets.

@tuxcanfly
Last active December 11, 2015 12:59
Show Gist options
  • Save tuxcanfly/4604806 to your computer and use it in GitHub Desktop.
Save tuxcanfly/4604806 to your computer and use it in GitHub Desktop.
class ImportFieldForm(LazyModelForm):
label = forms.ChoiceField(choices=(), required=False)
header = forms.ChoiceField(choices=(), required=False, error_messages={'valid': 'Please choose a star rating'})
class Meta:
model = ImportField
def __init__(self, *args, **kwargs):
self.labels = kwargs.pop('labels')
self.headers = kwargs.pop('headers')
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
MultiField('',
'header',
'label',
'DELETE',
),
)
super(ImportFieldForm, self).__init__(*args, **kwargs)
# TO DO -- GET VALUE OF selected HEADER and BASED ON HEADER DISPLAY TEXT WIDGET OR CHOICES WIDGET
header = self.data.get('header', None)
if header:
print header # should print the selected header
self.fields['header'].choices = list((x, x) for x in self.headers)
self.fields['header'].choices = [('', ''), ] + self.fields['header'].choices
self.fields['label'].choices = ((x, x) for x in self.labels)
self.fields['label'].choices = [('', ''), ] + self.fields['label'].choices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment