Django Tutorial: Adding Foreign User ID to Model

django

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 manage.py 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.

*