| | 274 | |
|---|
| | 275 | Storing additional information about users |
|---|
| | 276 | ------------------------------------------ |
|---|
| | 277 | |
|---|
| | 278 | If you'd like to store additional information related to your users, |
|---|
| | 279 | Django provides a method to specify a site-specific related model -- |
|---|
| | 280 | termed a "user profile" -- for this purpose. |
|---|
| | 281 | |
|---|
| | 282 | To make use of this feature, define a model with fields for the |
|---|
| | 283 | additional information you'd like to store, or additional methods |
|---|
| | 284 | you'd like to have available, and also add a ``ForeignKey`` from your |
|---|
| | 285 | model to the ``User`` model, specified with ``unique=True`` to ensure |
|---|
| | 286 | only one instance of your model can be created for each ``User``. |
|---|
| | 287 | |
|---|
| | 288 | To indicate that this model is the user profile model for a given |
|---|
| | 289 | site, fill in the setting ``AUTH_PROFILE_MODULE`` with a string |
|---|
| | 290 | consisting of the following items, separated by a dot: |
|---|
| | 291 | |
|---|
| | 292 | 1. The (normalized to lower-case) name of the application in which the |
|---|
| | 293 | user profile model is defined (in other words, an all-lowercase |
|---|
| | 294 | version of the name which was passed to ``manage.py startapp`` to |
|---|
| | 295 | create the application). |
|---|
| | 296 | |
|---|
| | 297 | 2. The (normalized to lower-case) name of the model class. |
|---|
| | 298 | |
|---|
| | 299 | For example, if the profile model was a class named ``UserProfile`` |
|---|
| | 300 | and was defined inside an application named ``accounts``, the |
|---|
| | 301 | appropriate setting would be:: |
|---|
| | 302 | |
|---|
| | 303 | AUTH_PROFILE_MODULE = 'accounts.userprofile' |
|---|
| | 304 | |
|---|
| | 305 | When a user profile model has been defined and specified in this |
|---|
| | 306 | manner, each ``User`` object will have a method -- ``get_profile()`` |
|---|
| | 307 | -- which returns the instance of the user profile model associated |
|---|
| | 308 | with that ``User``. |
|---|
| | 309 | |
|---|
| | 310 | For more information, see `Chapter 12 of the Django book`_. |
|---|
| | 311 | |
|---|
| | 312 | .. _Chapter 12 of the Django book: http://www.djangobook.com/en/beta/chapter12/#cn226 |
|---|