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 - This is a table where I add any user ( other than owner ) if they are member of the project.
class ProjectMember(models.Model):
project = models.ForeignKey(Project)
member = models.ForeignKey(User)
added_on = models.DateTimeField()
What I am trying to do is get a list of projects which the current user is either owner or member of. So, I have this in my view :
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