python - How do you extract unique queryset from queryset of objects with ManyToManyField -
i have channel model object follows:
def channel(models.model): users = models.manytomanyfield(user, blank=true, null=true, related_name='channels') manager = models.foreignkey(user, related_name='manager_channels')
i want list of users channels managed current user, so:
managed_channels = channel.objects.filter(manager=user) # users of managed_channels queryset
is there efficient way list without iterating on managed_channels queryset , extracting users , compiling unique list?
try reverse relation:
#add .distinct() if duplicate users. users = user.objects.filter(channels__manager=request.user)
Comments
Post a Comment