I’ll start by saying that my database skills are weak, and it’s quite possible I’m just designing this wrong.
I’m working on a Django 1.3 application that would allow customers to log in to view various aspects of their “account”. One of the models is “Customer”, and it makes sense to me that I add a field in that model for “username” so that I can show projects, payments etc that belong to each customer.
I’ve got much of my schema set up but I can’t figure out how to make a “username” field that references the django login name. You average field looks something like
projects = models.ManyToManyField('Project')
website = models.URLField()
updates to clarify
what I think I need is:
username = models.ForeignKey(WhereverDjangoKeepsTheUserModel)
SOLVED
I needed
from django.contrib.auth.models import User
and
username = models.ForeignKey(User)
Accepting Jack M’s answer because it helped me find the specific piece I needed.
You are probably looking for a ForeignKey relationship.
Then from within your view:
To read more about this, check out the “Your First Model” section in chapter 5 of The Django Book.