I have a model Follow:
class Follow(BaseModel):
follower = django.db.models.ForeignKey(
'User',
related_name='_follows_we_are_follower'
)
followee = django.db.models.ForeignKey(
'User',
related_name='_follows_we_are_followee'
)
datetime_canceled = django.db.models.DateTimeField(null=True, blank=True)
When I'm handling a user, how do I get all the users he's following? I assume I want something like "Give me all the users for which exists a Follow object with a datetime_canceled of None, and the follower is that user, and then for all those follows get me the users that are in the followee field." How do I write this in Django?
I'm quite away from django now So, syntax would be wrong. But I guess you want something like this:
User.objects.filter(Follow_related_name__in = ['_follows_we_are_follower', ,'_follows_we_are_followee'], datetime_canceled__is_null =True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With