For example, I want to get a list of Users. My current queryset looks like this
creator_list = User.objects.filter(
Q(userprofile__place__managers=user) |
Q(pk=user.pk)
)
I found out I could get the same result with ...managers=user.pk
creator_list = User.objects.filter(
Q(userprofile__place__managers=user.pk) |
Q(pk=user.pk)
)
I used to write ...=user.pk all the time until I realized I can simply drop the pk part. So in the second Q() clause, is it possible to remove the pk part as well? Thus I want to make it look like
creator_list = User.objects.filter(
Q(userprofile__place__managers=user) |
Q(something=user)
)
I understand that pk takes in the primary key, which is an integer, of the model, but why do I need to specify it when I already know that I want the filter through the User model.
Unfortunately no. A field is required for field lookups, therefore the PK must be used since there is no way to refer specifically to the row indicated by a model.