Django Tutorial: Adding Foreign User ID to Model


Adding Foreign Key

First, declare the authentation User object:

[code lang=”py” inline=”yes”]from django.contrib.auth.models import User[/code]

and then add to your model:

[code lang=”py” inline=”yes”]user = models.ForeignKey(User)[/code]

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

[code lang=”bash” inline=”yes”]python syncdb[/code]

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



Good luck!

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.