1👍
✅
from yourapp.models import PhoneNumber
class CustomerCreateForm(forms.ModelForm):
'''
Base form for creating customers
'''
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
'Personal Information',
'phone_number',
),
FormActions(
Submit('submit' , 'Submit' , css_class='btn btn-success'),
Button('cancel' , 'Cancel' , css_class='btn btn-warning',
onclick='javascript:history.go(-1);'),
)
)
super(CustomerCreateForm, self).__init__(*args, **kwargs)
self.fields["phone_number"].choices = \
[(item.number, item.number) for item in PhoneNumber.objects.all()]
class Meta:
model = Customer
exclude = (
'create_user',
'modify_user'
)
Source:stackexchange.com