Monday, December 16, 2013

Re: Adding Objects to Query Set

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 2nd table.

e.g. following is the full list of projects. + denotes that I am owner. * denotes where I am a member.

Project1
Project2 ( + )
Project 3
Project4 ( * )

When I do a projects = Project.objects.filter(owner=request.user) I get a query set like :
[<Project:Project1>]

Now, when I do member_projects= Member.objects.filter(member=request.user) I get a query set like:
[<ProjectMember: Project4>]

So far so good. I dont have any issues from them. However, in my templates, now I need to pass on 2 querysets because these objects are different. I have 2 loops for listing the projects. one for projects where I print the name as  {{ o.name }} and one for the ProjectMember where I print the name as o.project.name . I want to make the code neater and have just one loop :)

Now from the 2nd queryset ( since the object type is different), I want to take out the actual project objects and add to the 1st set. Thats where I am hitting a roadblock.

for o in member_projects
   o.project

works fine, as I get the project object.

However, now I want to add this project into the 1st queryset  - and there i am not able to.

Hope this clears what I am trying to achieve!

V. 

On Mon, Dec 16, 2013 at 8:21 PM, Sebastian Morkisch <semox78@googlemail.com> wrote:
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_queryset(self):
   return Project.objects.filter(owner=self.request.user.id) <-- see that id?

Best regards,
Sebastian

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9dec582e-41c0-47b1-a9ed-65850eac8585%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPiONwka6BorE6ec8vRXgAy6X85HiCctZy55rR5MaetuzafSEw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate