Re: Help with a query :$

2010-01-05 Thread greatlemer
On Jan 5, 2:24 pm, Bill Freeman wrote: > On Mon, Jan 4, 2010 at 11:00 PM, Marc Aymerich wrote: > > class user(models.model): > > person = models.OneToOneField(person) > > I presume that you meant: > >           person = models.OneToOneField(employee) > > Is so, then greatlemer's method will work.

Re: Help with a query :$

2010-01-05 Thread Bill Freeman
On Mon, Jan 4, 2010 at 11:00 PM, Marc Aymerich wrote: > class user(models.model): > person = models.OneToOneField(person) I presume that you meant: person = models.OneToOneField(employee) Is so, then greatlemer's method will work. Or, especially if you will have use for the employee

Re: Help with a query :$

2010-01-05 Thread Daniel Roseman
On Jan 5, 7:09 am, greatlemer wrote: > On Jan 5, 4:00 am, Marc Aymerich wrote: > You want to use filter [1] with something like: > user.objects.filter(employee__company__name='companyname') > >     > [1]http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-sp... > -- > Or simply us

Re: Help with a query :$

2010-01-04 Thread Marc Aymerich
On Tue, Jan 5, 2010 at 8:09 AM, greatlemer wrote: > On Jan 5, 4:00 am, Marc Aymerich wrote: > > Hi! > > I have a model like this: > > > > class company(models.model): > > name = models.CharField(mx_length=20) > > class employee(models.model): > > comany = models.ForeignKey(company) > > class us

Re: Help with a query :$

2010-01-04 Thread greatlemer
On Jan 5, 4:00 am, Marc Aymerich wrote: > Hi! > I have a model like this: > > class company(models.model): > name = models.CharField(mx_length=20) >  class employee(models.model): > comany = models.ForeignKey(company) >  class user(models.model): > person = models.OneToOneField(person) > > One com

Help with a query :$

2010-01-04 Thread Marc Aymerich
Hi! I have a model like this: class company(models.model): name = models.CharField(mx_length=20) class employee(models.model): comany = models.ForeignKey(company) class user(models.model): person = models.OneToOneField(person) One company can have multiple employees but one employee only can ha

Re: Need some help with a query if you can :)

2008-02-24 Thread Darthmahon
Hi Guys, Just wondered if anyone else could help out on this one? To me it doesn't seem like it's a difficult thing to do, I just can't get it to work :( Cheers, Chris On Feb 23, 11:48 am, Darthmahon <[EMAIL PROTECTED]> wrote: > Hmmm ok, can't get this to print anything. When trying to print th

Re: Need some help with a query if you can :)

2008-02-23 Thread Darthmahon
Hmmm ok, can't get this to print anything. When trying to print the threads array it does this: [, []] [, []] So, it is looping through my friends properly, but it not getting their threads. To be honest, ideally I just want to print a list of all the threads my friends are in, and not a list of

Re: Need some help with a query if you can :)

2008-02-22 Thread Julien
If you look at my code, I put "related_name='threads'" If you don't specify that, then it is automatically set to "thread_set" (see here: http://django.tomsk.ru/documentation/models/reverse_lookup/) Also, in your view, do this instead: return render_to_response('people/threads.html', { "friends"

Re: Need some help with a query if you can :)

2008-02-22 Thread Darthmahon
Ok, just tried this: View: - # get threads for friends threads = [] for friend in friends: threads.append([friend, friend.thread_set.all()]) - This appears to print something back, but it looks like it is just printing my friends. Not sure how to loop through this result properly in

Re: Need some help with a query if you can :)

2008-02-22 Thread Darthmahon
Hi Julien, Just gave that a go, getting an error: 'User' object has no attribute 'threads' I'm guessing that because I am referring to the User model, which has no direct relation to the Thread module, this won't work? Julien wrote: > Hi, how about this? (I haven't tested it myself) > > Models

Re: Need some help with a query if you can :)

2008-02-22 Thread Julien
Hi, how about this? (I haven't tested it myself) Models: --- class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) friends = models.ManyToManyField(User, blank=True, related_name='friends') class Thread(models.Model): title = models.CharField(maxlength=200

Need some help with a query if you can :)

2008-02-22 Thread Darthmahon
Hey, I have three models but I can only handle the relationship between two at any one time. Basically I have a page that needs to show a threads the current user's friends are currently participating in. I.E. something like this: Thread: ABC Participating: Friend 1 Thread: XYZ Participating: