use the related name on the staff model for project field with __ lookup as
in
class Staff(models.Model):
.............
.........
....
project = foreignkey relationship (related_name='staffs')
SO the query would be Projects.objects.filter(staffs__project_id=F('pk'))
On Tuesday, 15 June 2021 at 14:13:26 UTC+5:30 [email protected] wrote:
> Team,
>
> I am a little bit confused: I have a table callect Projects and another
> called Staffs. I want a particular staff member to view only the project
> he/she has a role in. In the Staffs table I have a project foreign key
> project_id. But I am confused about how to construct the query. I think of
> the SQL as below
>
> *Select * from Projects where Projects.id = Staffs.projects_id *
>
> I want to transform this query into a django query.
>
> Assist please
>
> --
> *Eugene*
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/6f74a18a-9798-4080-a462-6eff3231d7acn%40googlegroups.com.