Adding Objects to Query Set
Hi
I am not able to figure this out. I want to add objects to a query set. I have 2 models :
class Project(models.Model):
...
...
owner = models.ForeignKey(User)
class ProjectMember(models.Model):
project = models.ForeignKey(Project)
member = models.ForeignKey(User)
added_on = models.DateTimeField()
def mylist(request):
projects = Project.objects.filter(owner=request.user)
member_of = ProjectMember.objects.filter(member = request.user)
# Now find all projects the user is a member of and add to the projects list
all_projects = projects
for m in member_of:
all_projects |= m.project
return render (request, "project/projects_mine.html", {'projects':projects})
I am doing something wrong here as the line all_projects |= m.project is not working. I tried with a += also.
How can I achieve what I am trying to do ?
Vibhu
--
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/CAPiONwm9%2Bnp_BROqjVEfmDaE_KgAnYnhv8u-GuiFBG7q2QeuaA%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