Re: Adding Objects to Query Set

2013-12-17 Thread Vibhu Rishi
I will try this out also. Thanks! On Tue, Dec 17, 2013 at 1:57 PM, Arnold Krille wrote: > Hi, > > define related names in ProjectMember: > > class ProjectMember(models.Model): > project = models.ForeignKey(Project, related_name='members') > member = models.ForeignKey(User) > added_o

Re: Adding Objects to Query Set

2013-12-17 Thread Vibhu Rishi
This seems to be working with a slite modification. the _set was giving an error. So, I changed to : Project.objects.filter(projectmember__member=request.user) I am not sure if that will just return 1 result or all the results. I have to check that out. Vibhu On Mon, Dec 16, 2013 at 11:26 PM,

Re: Adding Objects to Query Set

2013-12-17 Thread Arnold Krille
Hi, define related names in ProjectMember: class ProjectMember(models.Model): project = models.ForeignKey(Project, related_name='members') member = models.ForeignKey(User) added_on = models.DateTimeField() The full query to get all Projects the User is either member or leader: Proje

Re: Adding Objects to Query Set

2013-12-16 Thread antialiasis
Rather than fetching ProjectMember.objects.filter(member=request.user), you want to fetch Project.objects.filter(projectmember_set__member=request.user). That will get you Project objects rather than ProjectMember objects. On Monday, December 16, 2013 1:47:13 PM UTC, Vibhu Rishi wrote: > > Hi

Re: Adding Objects to Query Set

2013-12-16 Thread Vibhu Rishi
Hi Andrew, The set seem to add on properly. How do i now access the project detail ? When I try to iterate over it since this set is made of 2 different object types, it fails for one of them. e.g. i have in the project model attribute as 'name' for the project. so when i iterate over the list li

Re: Adding Objects to Query Set

2013-12-16 Thread Vibhu Rishi
Hi Sebastian, Not really. I want the list of project objects which is coming ok by filtering on the user object. I checked it from commandline, and I am getting it correctly. The problem is the 2nd table. I want to get the projects from the 1st table when the user is a member as specified in the

Re: Adding Objects to Query Set

2013-12-16 Thread Andrew Farrell
It sounds like you just want a set of projects and don't actually need a querySet. You can do this with projects = set( Project.objects.filter(owner=request.user).all() ) member_projects = set( ProjectMember.objects.filter(member = request.user) ) total_projects = set(projects) | set(member_project

Re: Adding Objects to Query Set

2013-12-16 Thread Sebastian Morkisch
Hi I am working on the same thing. Same here, one project model, one extended User model. Well, when I printed the request, I got the Usename, which is not an id, but you'd like to compare ids. Is that correct? So perhaps you're closer to a solution, if you have a method like this: def get_que

Adding Objects to Query Set

2013-12-16 Thread Vibhu Rishi
Hi I am not able to figure this out. I want to add objects to a query set. I have 2 models : 1. Projects which is basically a list of projects. I have a field which defines the owner of the project. e.g. : class Project(models.Model): ... owner = models.ForeignKey(User) 2. ProjectMember