I am making a profile form in Django. There are a lot of optional extra profile fields but I would only like to show two at a time. How do I hide or remove the fields I do not wan to show dynamically?
Here is what I have so far:
class UserProfileForm(forms.ModelForm):
extra_fields = ('field1', 'field2', 'field3')
extra_field_total = 2
class Meta:
model = UserProfile
def __init__(self, *args, **kwargs):
extra_field_count = 0
for key, field in self.base_fields.iteritems():
if key in self.extra_fields:
if extra_field_count < self.extra_field_total:
extra_field_count += 1
else:
# do something here to hide or remove field
super(UserProfileForm, self).__init__(*args, **kwargs)