I just started a Django project (there are no apps in it). I activated the admin in settings file and can access the Django administration page. There is a column in Django page to add users; while adding users I get only three fields under personnal info, but I need to store some more information about users. I Googled around and found that I can use user profiles to accomplish this. I tried, but I am having problems.
My aim is to add three more fields to the user table:
- role
- contact number
- other
I need details like: which function I need to write and where to do this.
I found this, but I do not know where I need to write these steps. I would greatly appreciate a more clear explanation of this.
Django User Profiles is what you need. The blog you linked to has clear steps on how to do it. You can check out the Django documentation. http://www.turnkeylinux.org/blog/django-profile also provides a good explanation.
Basically you need to create a new model with User as ForeignKey and define the model in the
settings.pyasAUTH_PROFILE_MODULE = "django_app.your_profile_modelname". Create the profile and save it just like any other model, and access it usinguser.get_profile()Adding a couple of things in response to your questions below:
First, do not create apps as a directory. Use
startapp <appname> [destination]as described here. That will create the app directory.Second, you have to add the app to
INSTALLED_APPSin the project’s settings file, do asyncdb. Basically, follow the steps in Django tutorial on writing your first app.Third,
UserProfileis a separate model. It is not an extension ofUser. It is associated with theUserjust because you addedUseras theForeignKey.Fourth, to be able to see the user profile model in admin, you do exactly what you would do to add any other model to admin page. Create a file names
admin.pyunder your app with: