Anonymous user
Adding a field to the profile: Difference between revisions
no edit summary
imported>Mark No edit summary |
imported>Mark No edit summary |
||
Line 191:
'birthday': person.birthday,
'understands': data['tags_flat'].get('understands', ''),
</pre></div>
=== Edit 4: Adding the Form ===
As you saw while adding the birthday field to the view, a form is being used by thew view to capture the data entered by the user. If you look in the edit_person_info_do(request) function, you should notice this line:
<div class="example"><pre>
edit_info_form = mysite.profile.forms.EditInfoForm(request.POST, prefix='edit-tags')
</pre></div>
This tells us that in the forms.py file (mysite.profile.'''forms'''.EditInfoForm), there is a class, EditInfoForm, which may need to be changed.
Open up the 'mysite/forms.py' file and search for EditInfoForm. You should notice a line added for 'irc_nick', so go ahead and edit the class to add a new line for the 'birthday' field.
<div class="example"><pre>
irc_nick = django.forms.CharField(required=False, widget=django.forms.TextInput())
birthday = django.forms.DateField(required=False, widget=django.forms.DateInput())
understands = django.forms.CharField(required=False, widget=django.forms.Textarea())
</pre></div>
Line 197 ⟶ 215:
The next things to do are:
* Make the template changes so the new field can be updated and appears in the profile block.▼
▲* Make the template changes so the new field appears in the profile block.
* [[Making schema changes|Write a migration file]] to add that column to our database.
* Write a test.
|