Since listing
field has related_name="watchlists"
, we can filter using related_name like this:
Listing.objects.filter(watchlists__user = X) # X is a user instance.
Note that __
is used for field lookups. __user
is for user field lookup.
If listing
field does not have any related name, we can filter using model name (Watchlist
) with _set
to the referencing model.
Listing.objects.filter(Watchlist_set__user = X) # X is a user instance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…