Django Tutorial: Adding Foreign User ID to Model

Django Tutorial: Adding Foreign User ID to Model

django

A short tutorial on adding a foreign key reference to Django’s built-in User model, linking your model’s records to authenticated users.

from django.contrib.auth.models import User

and then add to your model:

user = models.ForeignKey(User)

  That’s it! Don’t forget to update your DB (you may need to remove your current table) by running on Bash:

python manage.py syncdb

Note: I’m using Django on CentOS. the last command may be different in other distributions.

 

 

Good luck!