Anonymous user
Adding a field to the profile: Difference between revisions
no edit summary
imported>Mark |
imported>Mark No edit summary |
||
Line 150:
</pre></div>
= Making the birthday dynamic =
=== Edit 2: Adding a field to the Person model ===▼
If you take a look at template you just edited, you will notice that the person's website was referred to as "person.homepage_url". Since you also know that the code we want to edit is most likely in the "profile" module, you should start by looking in models.py, located in the "mysite/profile/" folder.
Line 163 ⟶ 165:
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.
Line 193 ⟶ 195:
</pre></div>
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:
Line 212 ⟶ 214:
Earlier you added a birthday to the base_profile.py file. This changed allowed you to see the birthday when viewing a profile. Now let's take it a step further and change it so the birthday is retrieved from the person's profile rather than being hard coded to January 1, 1980!
Line 259 ⟶ 261:
</pre><div>
Next we need to sync the database and create the migration file. This is a good time for you to save your work. So, let's do that now.
Line 287 ⟶ 289:
</pre></div>
= Managing the Database =
=== Edit 6: Syncing the database and creating a migration ===▼
Django has the ability to automatically save model changes to the database, however will only do this for new models. Once a model has been created, you must either manually make the change, or use a tool such as 'South' to make the change for you. South is what we refer to when speaking of migrations. Go ahead and try to sync the database and you will see the mysite.profiles does not get updated, even though you have added a new field to the model.
Line 349 ⟶ 353:
</pre></div>
Running 'git status' will show you that a couple of changes have taken place.
Line 436 ⟶ 440:
</pre></div>
= Submitting a patch =
* Information on how to submit a patch should be here. Links to [http://openhatch.org/missions/git git mission] would be helpful.
=== Inflection point ===
|