Adding a field to the profile: Difference between revisions

no edit summary
imported>Mark
imported>Mark
No edit summary
Line 162:
</pre></div>
 
 
=== Edit 3: Adding the new field to the view ===
 
Adding a field to the model will ensure that we have a place to store the new field. You now need a way to access and update the data in this field. In Django, this is the responsibility of the view.
 
Find the view.py file located in the "mysite/profile" folder. Since you know that another field, 'irc_nick' is handled the same way as you want the new birthday field handled, you can easily find the right places to make changes to the code by searching for 'irc_nick'. Do that now and you will find the field added in the following functions.
 
In the edit_person_info_do(request) function, you will find the following line:
<div class="example"><pre>
# grab the irc nick
person.irc_nick = edit_info_form['irc_nick'].data
</pre></div>
 
Now edit that to add in a similar line for our new birthday field. Note: We will soon add the new field to the form.
<div class="example"><pre>
# grab the irc nick
person.irc_nick = edit_info_form['irc_nick'].data
 
# grab the birthday
person.birthday = edit_info_form['birthday'].data
</pre></div>
 
Continuing your search, you will notice that the 'irc_nick' field also appears in the edit_info function. Continue to make a change so that our birthday field appears there as well. Note: Don't forget the comma at the end of the line!
 
<div class="example"><pre>
'homepage_url': person.homepage_url,
'irc_nick': person.irc_nick,
'birthday': person.birthday,
'understands': data['tags_flat'].get('understands', ''),
</pre></div>
 
=== Inflection point ===
Line 167 ⟶ 197:
The next things to do are:
 
* Create a form to capture the new field
* Add something like person.homepage_url so that each person can have their own birthday.
* 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 form so people can edit their birthday.
* Write a test.
* Submit a patch.
 
= Testing =
Anonymous user