I have two models Community and UserCommunity
Community Model
class Community(models.Model):
# Community name
name = models.CharField(max_length=64)
slug = models.CharField(max_length=40, blank=True)
admins = models.ManyToManyField(
settings.AUTH_USER_MODEL, related_name="admins", blank=True
)
admins = models.ManyToManyField(
settings.AUTH_USER_MODEL, related_name="admins", blank=True
)
members = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name="members",
blank=True,
)
------
UserCommunityModel
class UserCommunity(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=CASCADE, related_name="user"
)
group = models.ForeignKey(
Community, on_delete=CASCADE, related_name="group")
role = models.CharField(max_length=15, blank=True, null=True)
# True is in community, false is not in community
active = models.BooleanField(null=True, blank=True)
I need to get all the community objects where a user is not part of the community and the community should have at least 1 member
I've tried using this
Community.objects.filter(group__user=request.user.id, group__active=False,state=location.state, group_discoverability="public").exclude(
hofAdmins__isnull=True, admins__isnull=True, members__isnull=True)[:10]
But this returns the communities which has a UserCommunity object, UserCommunity object is created when user joins the community. Any help would be appreciated, thanks!