Hi! I have this models:
class Project(models.Model):
users = models.ManyToManyField(User, through='Project_User')
class Project_User(models.Model):
project = models.ForeignKey('Project')
user = models.ForeignKey(User)
property = models.BooleanField()
Not all Projects have own Project_User rows.
Thing, what I need is get queryset of all Projects where field "property" of current user != true or Project_User row of current user doesn't exists. Is here any way to do this using django's ORM? As result, I need Queryset object for applying some other filters to it.
Using custom SQL I can do it. Current user have id==XXXX:
SELECT * FROM "app_project" LEFT OUTER JOIN "app_project_user"
ON ("app_project"."id" = "app_project_user"."project_id"
AND ("app_project_user"."user_id" = XXXX OR "app_project_user"."user_id" IS NULL))
WHERE ("app_project_user"."property" = false OR "app_project_user"."property" IS NULL);
I hope, it is possible, but I don't know how, yet..
Thanks for any help!