Hello!
In general, I will explain the situation first:
I have a model
class Friends(models.Model, MixinModel): by = models.ForeignKey(Profile, related_name="from_friend") friend = models.ForeignKey(Profile, related_name="to_friend") approve = models.CharField(max_length=2, choices=RELATION_STATUS, default=State.No)
It is an intermediate model for linking Profile and Profile. In the inside of the ListView profiles, I override the get_queryset (it turns out, this is the queryset of profiles) by the approve parameter of the intermediate model and the current user. I didn’t think of anything except filtering by
f = Friends.object.filter (approve = State.No)
, get from this filter the id-swords of the by
field and compare them with the id-schnics of the default queryset.
Can this be done somehow more beautifully and less costly? It seems to me that there should be a way to filter models according to an intermediate model. after all, they invented it?