Need to create form where users can add or delete fields acc to their need like user can add email, phone no field in the form or like family info, etc or if the user doesn't want that field he can delete the field. Which Django property I can you to create this form or field.
It's not hard to dynamically create a form, although you need something to determine what it should contain for each request. The three-argument form of (Python) type can be used. For example,
fields = {
  'foo': forms.CharField( max_len=80 )
  'bar': forms.IntegerField() 
}
MyForm = type( 'MyForm', (forms.Form, ), fields)
...
form = MyForm()
which is the same as
class MyForm( forms.Form):
    foo = forms.CharField( max_len=80 )
    bar = forms.IntegerField() 
...
form = MyForm()
except that you can construct the contents of fields dynamically, using some runtime entity to decide what fields with what names and of what type should be in the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With