Django Tutorial: Adding Foreign User ID to Model


Adding Foreign Key

First, declare the authentation User object:

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 syncdb

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



Good luck!

Development Specialist, Artist and Activist
Personal Website

Leave a Reply

Your email address will not be published.